Is there a PHP function for swapping the values of two variables?

前端 未结 19 960
终归单人心
终归单人心 2020-12-02 08:36

Say for instance I have ...

$var1 = \"ABC\"
$var2 = 123

and under certain conditions I want to sw

19条回答
  •  情书的邮戳
    2020-12-02 08:53

    It is also possible to use the old XOR trick ( However it works only correctly for integers, and it doesn't make code easier to read.. )

    $a ^= $b ^= $a ^= $b;
    

提交回复
热议问题