gpt4 book ai didi

PHP - 将两个数组(相同长度)合并为一个关联?

转载 作者:IT王子 更新时间:2023-10-28 23:46:26 25 4
gpt4 key购买 nike

其实很简单的问题..

is it possible in PHP to combine two separate arrays of the same length to one associative array where the values of the first array are used as keys in the associative array?

我当然可以这样做,但我正在寻找另一个(内置)功能,或更有效的解决方案..?

function Combine($array1, $array2) {
if(count($array1) == count($array2)) {
$assArray = array();
for($i=0;$i<count($array1);$i++) {
$assArray[$array1[$i]] = $array2[$i];
}
return $assArray;
}
}

最佳答案

array_combine($keys, $values)

PS:点击我的回答!它也是一个链接!

关于PHP - 将两个数组(相同长度)合并为一个关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1200885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com