Novice please give me some advice--how to traverse an array
QY
QY 2019-01-21 17:20:32
0
4
922

$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'),

),

);


##

QY
QY

reply all (3)
小月九日

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

foreach ($value as $val) {

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

}

}


    刘宁

    You can’t use key values like that

      Peter-Zhu
      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()

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!