Blogger Information
Blog 48
fans 0
comment 0
visits 36379
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组的遍历
雨天的博客
Original
672 people have browsed it

实例

<?php
//数组遍历
echo '<h3>for循环遍历关联数组</h3>';
$arr=['id'=>1,'grade'=>3,'name'=>'Tom','address'=>'USA'];
for ($i=0;$i<count($arr);$i++){
    echo key($arr).'=>'.current($arr).'<br>';
    next($arr);
}
echo '<h3>foreach循环遍历关联数组</h3>';
foreach ($arr as $key=>$value)
{
    echo $key,'=>',$value,'<br>';
}

echo '<h3>for循环遍历索引数组</h3>';
$lang=['css','js','html','php','vue.js'];
$str='';
for($i=0;$i<count($lang);$i++)
{
    $str.= $lang[$i].',';
}
echo rtrim($str,',').'<br>';//去掉最后的逗号

echo '<h3>while循环遍历索引数组</h3>';
$i=0;
while($i<count($lang))
{
    echo ($i<(count($lang)-1)) ? $lang[$i].',' : $lang[$i];
    $i++;
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!