Think, I have two arrays as showing below:
$a1 = [1=>444,2=>555,3=>666,4=>777];
$a2 = [1=>888,2=>999,3=>444,4=>'',5=>123,6=>215];
Then, my new array should be :
Array
(
[1] => Array
(
['p1'] => 444
['p2'] => 888
),
[2] => Array
(
['p1'] => 555
['p2'] => 999
),
[3] => Array
(
['p1'] => 666
['p2'] => 444
),
[4] => Array
(
['p1'] => 777
['p2'] =>
)
)
I tried its as shown the code below. Its working for me, But my I know is there any other appropriate way to do this without looping in php?
foreach ($a1 as $k => $v) {
$nary[$k] = ['p1' => $v, 'p2'=>$a2[$k]];
}