I'm running two for each loops and pushing one of them into the other one. This works fine, except if my I have more than one match. In that case, I'm only getting the last one. Sorry about the title, not too sure how to call this question in one line.
foreach($items as &$item) {
foreach($fruits as &$fruit) {
$i = 0;
if($fruit['for']==$item['id']) {
$item["fruits"][$i] = $fruit;
$i++;
}
}
}
First array :
array(114) {
[0]=>
array(5) {
["id"]=>
string(2) "76"
...
}
...
}
Second array :
array(47) {
[0]=>
array(5) {
["id"]=>
string(1) "4"
["for"]=>
string(2) "76"
...
}
...
}
With multiple matches of the if($fruit['for']==$item['id']) logic, I'd like the following output.
array(114) {
[0]=>
array(6) {
["id"]=>
string(2) "76"
...
["fruits"]=>
array(2) {
[0]=>
array(5) {
["id"]=>
string(1) "4"
["for"]=>
string(2) "76"
...
}
[1]=>
array(5) {
["id"]=>
string(2) "33"
["for"]=>
string(2) "76"
...
}
}
}
}
What am I doing wrong?