我有多个数组,我想将它们放入一个数组中以便对其进行排序:
$weight = array($weight);
$dev = array_combine($missing, $weight);
echo "<pre>";
print_r($dev);
echo "</pre>";
输出:
Array (
[angular] => 2
)
Array (
[android sdk] => 3
) Array (
[application] => 1
)
现在如何将上面的数组变成这个?
Array (
[android sdk] => 3
[angular] => 2
[application] => 1 )
我已经在此站点上找到的解决方案中尝试了以下方法,但是它返回NULL:
$weight = array($weight);
$dev = array_combine($missing, $weight);
$result = call_user_func_array("array_merge", $dev);
echo "<pre>";
print_r($result);
echo "</pre>";
编辑
这是我的$ missing数组,某些数组为空,因为未找到与某些关键字的匹配项:
Array
(
)
Array
(
[0] => angular
)
Array
(
[0] => android sdk
)
Array
(
[0] => application
)
Array
(
)
以下是$ weight中的值:
3 2 3 1 3
我怎么能得到这个?
Array (
[android sdk] => 3
[angular] => 2
[application] => 1 )
答案 0 :(得分:2)
您可以使用array_merge
功能。
因此,代码将为
array_merge($array1, $array2);
答案 1 :(得分:1)
使用array_merge
:
$array1 = [1,2,3];
$array2 = [4,5,6];
$result = array_merge($array1, $array2);
print_r($result);
导致:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)