简体   繁体   中英

Making a Multidimensional Array using loop in PHP

I wanted to have an array like this using a for / foreach loop in PHP because I'm going to pass an array. But it's difficult to make. And how will I display this in HTML?

$Food_Order = array(
                    array("Chicken",1,50),
                    array("Beef",2,5),
                    array("Fish",3,10),
                    array("Pork",4,15)
              ); 

Your question is not very clear. You can try the following. I hope it solves your requirement.

$Food_Order=array();
for($foodCounter=0; $foodCounter<4; $foodCounter++)
{
     //Assuming that $foodName, $orderQuantity and $foodPrice come from a Data Source
     $Food_Order[$foodCounter]=array($foodName, $orderQuantity, $foodPrice);
}

echo "<pre>";
print_r($Food_Order);
echo "</pre>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM