PHP遍历数组array()

2017-07-09 20:57:26

1. 使用foreach()

$urls= array('aaa','bbb','ccc','ddd'); 
foreach ($urls as $url){
    echo "This Site url is $url! <br />"; 
} 


2. 使用for()

$urls= array('aaa','bbb','ccc','ddd'); 
for ($i= 0;$i< count($urls); $i++){
    $str= $urls[$i];
    echo "This Site url is $str.<br />";
} 


3. 使用while()

$urls= array('aaa','bbb','ccc','ddd'); 
while(list($key,$val)= each($urls)) {
    echo "This Site url is $val.<br />"; 
}

近期文章