note 88678 added to function.settype

From: Date: Tue, 03 Feb 2009 16:32:18 +0000
Subject: note 88678 added to function.settype
Groups: php.notes 
Request: Send a blank email to php-notes+get-150150@lists.php.net to get a copy of this message
You can change variable type also in another way instead of using function settype(). <?PHP $a = '125'; //$a is string var_dump($a); $a *= 1; //this convert $a to integer var_dump($a); $a *= 1.0; //$a is converted to float var_dump($a); $a .= ''; //now $a is string again var_dump($a); $a = NULL; //and finally $a is null var_dump($a); ?> With this you can easily change variable type to string, float or integer (but you can't change float to integer). Positive side effect of this is that it is about 50% faster than using settype() function. This is because simple expression is executed more quickly than function. ---- Server IP: 147.32.160.17 Probable Submitter: 213.155.231.66 ---- Manual Page -- http://www.php.net/manual/en/function.settype.php Edit -- https://master.php.net/note/edit/88678 Del: integrated -- https://master.php.net/note/delete/88678/integrated Del: useless -- https://master.php.net/note/delete/88678/useless Del: bad code -- https://master.php.net/note/delete/88678/bad+code Del: spam -- https://master.php.net/note/delete/88678/spam Del: non-english -- https://master.php.net/note/delete/88678/non-english Del: in docs -- https://master.php.net/note/delete/88678/in+docs Del: other reasons-- https://master.php.net/note/delete/88678 Reject -- https://master.php.net/note/reject/88678 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150150) next »