search

Home  >  Q&A  >  body text

Novice please give me some advice--how to traverse an array

$arr=array(

'Teaching Department'=>array(

array('Li','18','Lady'),

array('Gao','20','Male'),

array('Zhang','21','Yaoren'),

),

'Propaganda Department'=>array(

array('Li','18','Lady'),

array('Gao','20' ,'Male'),

array('Zhang','21','Yaoren'),

),

'Finance Department'=>array (

  array('Li','18','Lady'),

  array('Gao','20','Male'),

array('Zhang','21','Yaoren'),

),

);


##

QYQY2178 days ago1026

reply all(4)I'll reply

  • 小月九日

    小月九日2019-01-26 15:42:22

    foreach ($arr as $key => $value) {

    foreach ($value as $val) {

    echo "Department:" .$key." Name: ".$val[0]." Age: ".$val[1]." Gender: ".$val[2]."<br>";

    }

    }


    reply
    0
  • 刘宁

    刘宁2019-01-23 09:42:32

    You can’t use key values ​​like that

    reply
    0
  • 天蓬老师

    天蓬老师2019-01-21 20:44:55

    1. This array syntax is no longer used, please use: [...]

    2. ##It can be implemented using a double loop, you can use foreach (), you can also use for()

    3. reply
      1
  • Cancelreply