当前位置 : 主页 > 网络编程 > PHP >

foreach遍历数组

来源:互联网 收集:自由互联 发布时间:2021-07-03
?php/* * foreach */ $fruits = array("lemon" , "orange" , "banana" , "apple");sort($fruits);$n = count($fruits);echo "Length of fruits is: ".$n."br/"; foreach ($fruits as $key = $val) { echo "fruits[".$key."] = ".$val."br/";} ?
 
<?php
/*
 * foreach
 */
   
$fruits  = array("lemon" , "orange" , "banana" , "apple");
sort($fruits);
$n = count($fruits);
echo "Length of fruits is: ".$n."<br/>";
  
foreach ($fruits as $key => $val) {
    echo  "fruits[".$key."] = ".$val."<br/>";
}
   
?>

网友评论