<?php$products=Array( Array(' Apple ', 2,8.5), Array(' Pork ', 2,20.5), Array(' Biscuits ', 2,10.2) ); //Loop Output for($i= 0;$i<Count($products);$i++) { Echo' <br/> '; for($j= 0;$j<Count($products[$i]);$j++) { Echo $products[$i][$j]; } }?>
An array of loops that contain a key:
<?PHP$item=Array( Array(' Item name ' = ' apple ', ' quantity ' =>2, ' price ' =>8.5),Array(' Item name ' = ' pork ', ' Quantity ' =>2, ' price ' =>28.5),Array(' Item name ' = ' toothpaste ', ' quantity ' =>1, ' price ' =>4.5));//method One: for($i= 0;$i<Count($item);$i++){ Echo' <br/> '; foreach($item[$i] as $key=$value){ Echo $key.‘ ------‘.$value. ' | ';}}//Method Two: for($i= 0;$i<Count($item);$i++){ Echo' <br/> '; while(!!List($key,$value)= each($item[$i])){ Echo $key.‘ ------‘.$value. ' | ';}}?>
A looping method for arrays in an array of PHP learning records