The php bit operator ^ evaluates the string

$a = "abc";  
$b= "def";  
  
$a = $a^$b;  
$b = $b^$a;  
$a = $a^$b; 


echo $b; //abc
echo $a; //def

explain the calculation process, why variables are exchanged

Php
Mar.10,2021

binary XOR exchange, any language is the same

clipboard.png

refer to https://blog.csdn.net/zxm1306.


1^1=0
0^0=0
1^0=1
0^1=1
$b^($a^$b)=$a^($b^$b)=$a
$a^($a^$b)=$b^($a^$a)=$b

suppose the binary value of $an is 1000 $b is 1010

// $a,$b  
//$a = $a^$b; // 1000  1010
//echo $a;    // 0010
//$b = $a^$b;      //1010 0010 =1000
//echo $b;   //1000
//$a = $a^$b;  //  0010  1000 = 1010
//echo $a; // 1010
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e61a14-45181.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e61a14-45181.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?