phparraysmultidimensional-arraysub-array

How to push a new row into a 2d array?


$shop = array(
    array("aaa", 1.25 , 15),
    array("bbb", 0.75 , 25),
    array("ccc", 1.15 , 7) 
);  

for ($row = 0; $row < 3; $row++) {
     for ($col = 0; $col < 3; $col++) {
         echo $shop[$row][$col] . "/";
     }
 }

Result:

aa / 1.25 / 15 / bbb / 0.75 / 25 / ccc / 1.15 / 7 /


How can I add a new row in this array?

For example:

array("ddd", 1.30 , 9)


Solution

  • You can do this by doing $shop[] = array("ddd", 1.30 , 9);