How can you combine two arrays?

后端 未结 6 1409
慢半拍i
慢半拍i 2020-12-12 08:15

They are simplified as follows which is enough for this question. This question is based on this answer.

1

[a][b][]

and

2

6条回答
  •  无人及你
    2020-12-12 09:08

    foreach($array1 as $a => $c)
    {
        $end_array[$c] = $array2[$a];
    }
    

    or

    // For every [a]
    foreach($array1 as $a => $c)
    {
        // Get the [b]
        $b = $array2[$a];
    
        // Add it to [a][c]
        $end_array[$a][$c] = $b;
    
        // Making it $end_array[$a][$c][$b] = array(....);
    }
    

提交回复
热议问题