如何使用for循环使用多维索引数组?

时间:2019-01-03 18:43:35

标签: php arrays multidimensional-array

我是初学者,请帮助我。

$userdata = [

    [
        ['user1', 'job1']
    ],
    [
        ['user2', 'job2']
    ],
    [
        ['user3', 'job3']
    ]
];

1 个答案:

答案 0 :(得分:-1)

$firstLevel = count($userdata);
for($a=0; $a<$firstLevel; $a++) {
  echo "First Level Key: $a<br>";

   $secondLevel = count($userdata[$a]);
   for($b=0; $b<$secondLevel; $b++) {
     echo "Second Level Key: $b<br>";

      $thirdLevel = count($userdata[$a][$b]);
      for($c=0; $c<$thirdLevel; $c++) {
         echo "Third Level Key: $c => Value: ". $userdata[$a][$b][$c] . '<br>';
      } 
    }
 }