Here is my code:
$arr = [
0 => [1, 2, 3, 4],
1 => ['one', 'two', 'three', 'four']
];
$res = [];
foreach ($arr as $item){
foreach($item as $i){
$res = [$i, $item];
}
}
print_r($res);
/*
Array
(
[0] => four
[1] => Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
)
As you see the result doesn't make any sense. Here is expected result:
Array
(
[0] => Array
(
[0] => 1
[1] => one
)
[1] => Array
(
[0] => 2
[1] => two
)
[2] => Array
(
[0] => 3
[1] => three
)
[3] => Array
(
[0] => 4
[1] => four
)
)
You know, nested loops always make me confuse. Anyway, does anybody know how can I achieve to the expected result?