Blogger Information
Blog 20
fans 0
comment 0
visits 14870
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用for()循环来遍历关联数组 2018.8.24
李逍遥
Original
1012 people have browsed it

实例

<?php

//用for()循环遍历关联数组
$language = ['PHP','HTML','PYTHON','JAVA','C++'];
$type = ['integer'=>'整数型','float'=>'浮点型','string'=>'字符串型','boolean'=>'布尔型','array'=>'数组型','object'=>'对象型'];
echo '//for()循环遍历索引数组<br>';
$ii = '';
for($i=0;$i<count($language);$i++){
    $ii .= $language[$i].'==';
}
echo rtrim($ii,'=='); //rtrim() 用于删除字符前后的空格,也可以自定义删除其他元素
echo '<hr>';
//for()循环,我觉得遍历索引数组更方便

//foreach()用来遍历关联数组
echo '//foreach()用来遍历关联数组<br>';
foreach ($type as $key=>$value){
    echo $key.'=>'.$value,'<br>';
}

运行实例 »

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


Correction status:qualified

Teacher's comments:
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