Looking for homework answers?
Lost
Lost 2018-03-21 15:53:23
0
6
1549

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

Lost
Lost

reply all(6)
咸鱼
<?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_u188464

<?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('李','18','人妖'),

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

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

),

);


foreach($arr as $ker=>$vase)

{

echo $ker.'< br/>';

foreach($vase as $k=>$v)

{

foreach($v as $x=>$y )

                                                                                                          echo $y; ';

}

}

Echo' & LT; br/& gt;

#}

## e ==============='.'<br/>';

}

?&gt ;

sky
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

没有输入昵称,请重新填写

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

快看,是李小贱!!!

What effect do you want? Generally use foreach to traverse

sky

I don’t understand what you want to do, traverse the array, how do you want to traverse it? What are the requirements?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template