dph19153 2018-07-26 11:51
浏览 166

如何在PHP中将多个数组合并为一个[重复]

This question already has an answer here:

I have a multiple arrays which I'd like to put into a single array in order to sort it:

$weight = array($weight);
$dev = array_combine($missing, $weight);

echo "<pre>"; 
print_r($dev); 
echo "</pre>";

Output:

Array (
  [angular] => 2
) 
Array (
  [android sdk] => 3
) Array (
  [application] => 1
)

Now how do I turn the array above into this?

Array (
    [android sdk] => 3
    [angular] => 2
    [application] => 1 )

I've tried the below from a solution that I've found on this site, but it returns NULL:

$weight = array($weight);
$dev = array_combine($missing, $weight);
$result = call_user_func_array("array_merge", $dev);

echo "<pre>"; 
print_r($result); 
echo "</pre>";

EDIT

Here is my $missing array, some arrays are empty because a match hasn't been found against some keywords:

Array
(
)
Array
(
    [0] => angular
)
Array
(
    [0] => android sdk
)
Array
(
    [0] => application
)
Array
(
)

Here are the value from $weight:

3 2 3 1 3

How can I get this?

Array (
    [android sdk] => 3
    [angular] => 2
    [application] => 1 )
</div>
  • 写回答

2条回答 默认 最新

  • douyanqu9722 2018-07-26 11:57
    关注

    You can use array_merge function.

    Therefore, the code will be

    array_merge($array1, $array2);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示