php如何循环遍历

1173
2021/3/20 14:41:57
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

php如何循环遍历

php中实现循环遍历的方法

1.使用each()函数实现循环遍历

$url=array('张三 => '26',

'李四' => '36',

'王五' => '41'

);

while(list($a,$b)=each($url))

echo "$a=$b <br/>";

2.使用list()函数实现循环遍历


$info = array('coffee','brown','caffeine');

list($drink,$color,$power) = $info;

list($drink,,$power) = $info; 

list( , ,$power) = $info;

3.使用while循环实现循环遍历


$contact = array(

"张三" => "26",

"李四" => "36",

"王五" => "41",

); 

echo '姓名'; 

while(list($key,$value) = each($contact)){

echo "<dd>$key : $value</dd>";

}

echo '</dl>';


辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 在PHP项目中使用FastAdmin有哪些成功案例