Traverse the array
<?php
$arr=array(
'Teaching Department'=>array(
) array(' Li','18','shemale'),
array('Gao','20','Male'),
array('Zhang','21 ','Monster'),
),
'Propaganda Department'=>array(
Array('Li','18','Shemale' ),
array('Gao','20','Male'),
array('Zhang','21','Yaoren'),
),
'Finance Department'=>array(
array('Li','18','Lady'),
array(' Gao','20','Male'),
array('Zhang','21','Yaoren'),
),
) ;
?>
I can’t figure it out. It’s different from what I thought. Please ask the teacher for help
咸鱼2018-05-30 16:32:44
<?php echo '<table width=500 border=1>'; $arr=array( '教学部'=>array( array('李某',18,'人妖'), array('高某',20,'男'), array('张某',21,'妖人'), ), '宣传部'=>array( array('李某',18,'人妖'), array('高某',20,'男'), array('张某',21,'妖人'), ), '财务部'=>array( array('李某',18,'人妖'), array('高某',20,'男'), array('张某',21,'妖人'), ), ); echo '<tr align=center><td>部门</td><td>姓名</td><td>年龄</td><td>性别</td></tr>'; foreach($arr as $key => $value){ echo '<tr><td rowspan=3 align=center>'.$key.'</td>'; foreach($value as $k1 => $v1){ foreach($v1 as $k2 => $v2){ if(!is_int($v2)){ echo '<td align=center>'.$v2.'</td>'; }else{ echo '<td align=center>'.$v2."岁</td>"; } } echo '</tr>'; } } echo '</table>'; ?>
phpcn_u1884642018-05-10 15:39:22
<?php
), 'Finance Department'=>array( array('李','18','人妖'), array( 'Gao','20','Male'), array('Zhang','21','Yaoren'), ), );
#}
## e ==============='.'<br/>';}?> ;
sky2018-03-21 17:42:24
echo '<table border="1" cellspacing="1" cellpadding="10">'; foreach($arr as $key=>$value) { echo '<tr><th>部门</th><th>姓名</th><th>年龄</th><th>性别</th></tr>'; echo '<tr>'; foreach($value as $ke => $va){ echo '<td>'.$key.'</td>'; foreach($va as $k => $v) { echo '<td>'.$v.'</td>'; } echo '</tr>'; } } echo '</table>';
I will obey you without paying anyone
没有输入昵称,请重新填写2018-03-21 17:40:42
foreach($arr as $key=> $value){
echo "Department".$key."<br>";
foreach($value as $ ke=>$va){
echo $ke."<br>";
foreach($va as $k =>$v){
echo $k.'--------'.$v."<br>";
}
}
}
This is a three-dimensional array, get it!
I won’t talk about the first loop, just get the index and value of the first layer;
The second loop is to get the index and value of the second loop, and the third loop is Get the index and value of the third loop
sky2018-03-21 17:27:36
I don’t understand what you want to do, traverse the array, how do you want to traverse it? What are the requirements?