note 96594 added to language.variables.basics
| From: | Edoxile at osu1 dot php dot net | Date: | Sat, 06 Mar 2010 21:25:25 +0000 |
| Subject: | note 96594 added to language.variables.basics | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166746@lists.php.net to get a copy of this message | ||
When wanting to switch two variables from content, you can use the XOR operator:
<?PHP
$a=5;
$b=3;
//Please mind the order of these, as it's important for the outcome.
$a^=$b;
$b^=$a;
$a^=$b;
echo $a.PHP_EOL.$b;
/* prints:
3
5
*/
?>
This will also work on strings, but it won't work on arrays and objects, so for them
you'll have to use the serialize() function before the operation, and the unserialize()
function after.
----
Server IP: 91.199.167.223
Probable Submitter: 83.83.52.10
----
Manual Page -- http://www.php.net/manual/en/language.variables.basics.php
Edit -- https://master.php.net/note/edit/96594
Del: integrated -- https://master.php.net/note/delete/96594/integrated
Del: useless -- https://master.php.net/note/delete/96594/useless
Del: bad code -- https://master.php.net/note/delete/96594/bad+code
Del: spam -- https://master.php.net/note/delete/96594/spam
Del: non-english -- https://master.php.net/note/delete/96594/non-english
Del: in docs -- https://master.php.net/note/delete/96594/in+docs
Del: other reasons-- https://master.php.net/note/delete/96594
Reject -- https://master.php.net/note/reject/96594
Search -- https://master.php.net/manage/user-notes.php