Home » Php » PHP: How to create multidimensional array inside a loop

PHP: How to create multidimensional array inside a loop

Posted by: admin February 25, 2020 Leave a comment

Questions:

I would like to create a multidimensional url inside a loop. The data coming in the loop I would like to store in a multidimensional like this:

    foreach($items as $item) {


        $array = array(

                  'name' => $item->house,
                   'surname'=>$item->car,
                   'url'=>$item->address
                   );

     }

The $items array contains 8 rows but the $array will show only the first row. not all 8 row.

QUESTION:
How can I display the value red and green if know the value blue?

 $a=array("name"=>"red","surname"=>"green","url"=>"blue");
How to&Answers: