标签:
数组遍历:
<?php $phone=array("iphone"=>"4000","xiaomi"=>"2000","vivo"=>"1000"); $arrlength=count($phone); foreach ($phone as $key=>$value){ echo "手机 :".$key." 价值:".$value." ¥<br>"; } $phone=array("iphone","xiaomi","vivo"); $arrlength=count($phone); $y=1; for ($i=0;$i<$arrlength;$i++){ $z=$i+$y; echo "第 $z 部手机是 $phone[$i] <br>"; } ?>
数组排序:
<?php $price=array("1100","500","4000"); $phone=array("iphone"=>"4000","xiaomi"=>"2000","vivo"=>"1000"); sort($price);//对数组进行升序 rsort($price);//对数组进行降序 $arrlength=count($price); for ($i=0;$i<$arrlength;$i++){ echo "$price[$i]<br>"; } asort($phone);//对数组值进行升序 arsort($phone);//对数组值进行降序 ksort($phone);//对数组键进行升序 krsort($phone);//对数组键进行降序 foreach ($phone as $key=>$value){ echo $key.":".$value."<br>"; } ?>
标签:
原文地址:http://www.cnblogs.com/dmchzp/p/5242140.html