不用临时变量交换两个变量的值

<?php
$a = 1;
$b = 2;

//===== 方法① =====//
$a ^= $b;
$b ^= $a;
$a ^= $b;

//===== 方法② =====//
list($a, $b) = array($b, $a);

//===== 方法③(前提:变量是int类型) =====//
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;

Copyright © 2024 码农人生. All Rights Reserved