How do you do nested loops for example to do the following:
Array 1 (contains list of items)
Array ( [0] => Array ( [Id] => 1 [Name] => Chocolate) [1] => Array ( [Id] => 2 [Name] => Milk ) [2] => Array ( [Id] => 3 [Name] => Strawberries ) [3] => Array ( [Id] => 4 [Name] => Yogurt ) )
Array 2 (cross reference)
Array ( [0] => Array ( [Id] => 9 [Name] => Chocolate [Eaten] => 0)
Array ( [1] => Array ( [Id] => 9 [Name] => Chocolate [Eaten] => False)
first it goes inside array one, and prints a list out:
Chocolate
Milk
Strawberries
Yogurt
The above list is then cross referenced to the second array to see if the item that item in list 1's eaten is False in the [Eaten] Row.
If it is an output is displayed e.g. echo "There are no more chocolates left"
So for I have done 2 foreach loops
<?php
//print out all the items
//out put the list of food
foreach($food['listFood'] as $name){
//before creating icon, perform if statement with second array
$currentName = "";
foreach($food as $row){
if($currentName != $name['Name']){
$currentName = $name['Name'];
?>
<span class='type'><?php echo $name['Name'];?></span><br />
<?php
$count = 0;
if($row['Name']==$name['Name'] && $row['Eaten']==null){
?>
echo "Food has not been eaten"<br />
<?php
}else {
?>
echo "Food has been eaten, there is no more left"<br />
<?php
}
}
}
}