我最近发现,+可以用于组合PHP中的数组。
将关联数组添加到关联数组:
$array1 = ["The" => "quick", "brown" => "fox"];
$array2 = ["jumps" => "over", "the" => "lazy dog"];
$combinedArray = $array1 + $array2;
/* Gives:
Array
(
[The] => quick
[brown] => fox
[jumps] => over
[the] => lazy dog
)
*/将关联数组添加到索引数组:
$array1 = ["The", "quick", "brown", "fox"];
$array2 = ["jumps" => "over", "the" => "lazy dog"];
$combinedArray = $array1 + $array2;
/* Gives:
Array
(
[0] => The
[1] => quick
[2] => brown
[3] => fox
[jumps] => over
[the] => lazy dog
)
*/将索引数组添加到关联数组:
$array1 = ["The" => "quick", "brown" => "fox"];
$array2 = ["jumps", "over", "the", "lazy dog"];
$combinedArray = $array1 + $array2;
/* Gives:
Array
(
[The] => quick
[brown] => fox
[0] => jumps
[1] => over
[2] => the
[3] => lazy dog
)
*/将索引数组添加到索引数组:
$array1 = ["The", "quick", "brown", "fox"];
$array2 = ["jumps", "over", "the", "lazy dog"];
$combinedArray = $array1 + $array2;
/* Gives:
Array
(
[0] => The
[1] => quick
[2] => brown
[3] => fox
)
*/其中一个和其他的不一样。
为什么最后一个不能用?
发布于 2021-11-13 10:53:01
https://stackoverflow.com/questions/69953538
复制相似问题