PHP foreach with Nested Array?

后端 未结 4 1048
广开言路
广开言路 2020-11-27 02:53

I have a nested array in which I want to display a subset of results. For example, on the array below I want to loop through all the values in nested array[1].

Ar         


        
4条回答
  •  孤城傲影
    2020-11-27 03:07

    Both syntaxes are correct. But the result would be Array. You probably want to do something like this:

    foreach ($tmpArray[1] as $value) {
      echo $value[0];
      foreach($value[1] as $val){
        echo $val;
      }
    }
    

    This will print out the string "two" ($value[0]) and the integers 4, 5 and 6 from the array ($value[1]).

提交回复
热议问题