$array = [1, 2, 3];
list($a, $b, $c) = $array;
echo $a; // 輸出1
echo $b; // 輸出2
echo $c; // 輸出3
// 交換兩個變量的值
$a = 1;
$b = 2;
list($a, $b) = [$b, $a];
echo $a; // 輸出2
echo $b; // 輸出1
$nestedArray = [1, [2, 3], 4];
list($a, list($b, $c), $d) = $nestedArray;
echo $a; // 輸出1
echo $b; // 輸出2
echo $c; // 輸出3
echo $d; // 輸出4
$assocArray = ['name' => 'Alice', 'age' => 25];
list('name' => $name, 'age' => $age) = $assocArray;
echo $name; // 輸出Alice
echo $age; // 輸出25
$array = [1, 2, 3, 4];
list(, $b, , $d) = $array;
echo $b; // 輸出2
echo $d; // 輸出4
list($a, $b, $c) = range(1, 3);
echo $a; // 輸出1
echo $b; // 輸出2
echo $c; // 輸出3