【发布时间】:2019-01-03 09:51:40
【问题描述】:
我有多个数组,我想将它们放入一个数组中以便对其进行排序:
$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 )
【问题讨论】:
-
尝试使用
+运算符而不是array_combine函数php.net/manual/en/language.operators.array.php -
array_combine(['android sdk', 'angular', 'application'], [3, 2, 1]);工作正常。你做错了什么。由于我们不知道您的变量中有什么,因此我们无法在这一点上为您提供帮助,但$weight = array($weight);是可疑的。 -
如何一次调用
print_r输出两个数组?