PHP循环遍历数组的3种方法list()、each()和while总结

180it 2020-02-19 PM 382℃ 0条

<?php
$url=array('百度'=>'www.baidu.com','新浪网'=>'www.sina.com','搜狐'=>'www.sohu.com');

while(list($a,$b)=each($url))
echo "$a=$b <br/>";
?>

<?php
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>

<?php
$contact = array("ID" => 1,"姓名" => "高某","公司" => "A公司","地址" => "北京市",);
list($key,$value) = each($contact);
echo "$key => $value"; //输出变量$key和$value,中间使用“=>”分割
?>

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP循环遍历数组的3种方法list()、each()和while总结