php数组—数组的常用遍历方式
[ 2011-03-30 15:25:20 | 作者: admin ]
for遍历只适合php的索引数组,尽量不要用for循环遍历
foreach循环结构
foreach($arr as $value)
foreach($arr as $key=>$value) echo "\$arr[".$key."]=".$value."<br>";
while() list() each()
多维数组中需要在foreach中再加一个foreach
例如:
$arr=array("hello"=>array(1,2,3,"bbb"=>4,5,6,"aaa"=>8),array
("one","two"),100=>array("a",1,"b",2));
foreach($arr as $key=>$value)
{
foreach($value as $k=>$value)
{
echo "\$arr[".$key."...
阅读全文…
foreach循环结构
foreach($arr as $value)
foreach($arr as $key=>$value) echo "\$arr[".$key."]=".$value."<br>";
while() list() each()
多维数组中需要在foreach中再加一个foreach
例如:
$arr=array("hello"=>array(1,2,3,"bbb"=>4,5,6,"aaa"=>8),array
("one","two"),100=>array("a",1,"b",2));
foreach($arr as $key=>$value)
{
foreach($value as $k=>$value)
{
echo "\$arr[".$key."...
阅读全文…
1