PHP options for extracting data from an array?

后端 未结 2 1907
我寻月下人不归
我寻月下人不归 2020-12-07 06:01

Given this two-dimensional array, each element has two indexes – row and column.



        
相关标签:
2条回答
  • 2020-12-07 06:38
    foreach($shop as $items){
     echo $items[0]." costs ".$items[1]." and you get ".$items[2]."<br />";
    }
    

    foreach seems more simple for me, plus it would handle if your key are not numeric like

    array(         'foo' => array("rose", 1.25 , 15),
                   'bar' => array("daisy", 0.75 , 25),
                   'foobar' =>array("orchid", 1.15 , 7) 
                 );
    

    personally I avoid to use for in PHP because it's less flexible then foreach in most case.

    0 讨论(0)
  • 2020-12-07 06:46

    You could also use

    foreach($shop as $shoprow)

    0 讨论(0)
提交回复
热议问题