PHP中遍历关联数组的方法
2013-07-23 17:12
507 查看
下面介绍PHP中遍历关联数组的三种方法:
foreach
程序运行结果:
football: good
swimming: very well
running: not good
each
程序运行结果:
football: good
swimming: very well
running: not good
list & each
程序运行结果:
football: good
swimming: very well
running: not good
foreach
<?php $sports = array( 'football' => 'good', 'swimming' => 'very well', 'running' => 'not good' ); foreach ($sports as $key => $value) { echo $key.": ".$value."<br />"; } ?>
程序运行结果:
football: good
swimming: very well
running: not good
each
<?php $sports = array( 'football' => 'good', 'swimming' => 'very well', 'running' => 'not good' ); while ($elem = each($sports)) { echo $elem['key'].": ".$elem['value']."<br />"; } ?>
程序运行结果:
football: good
swimming: very well
running: not good
list & each
<?php $sports = array( 'football' => 'good', 'swimming' => 'very well', 'running' => 'not good' ); while (list($key, $value) = each($sports)) { echo $key.": ".$value."<br />"; } ?>
程序运行结果:
football: good
swimming: very well
running: not good
相关文章推荐
- PHP遍历关联数组的方法介绍
- PHP:遍历关联数组的方法介绍
- [php] PHP中遍历关联数组的三种方法
- PHP中遍历关联数组的方法
- PHP中遍历关联数组的方法
- PHP中遍历关联数组的方法
- PHP中遍历关联数组的方法
- PHP遍历关联数组的方法介绍
- PHP遍历关联数组的几种方法
- PHP 哈希表,关联数组,遍历方法大全
- php遍历关联数组的三种方法
- PHP 遍历数组的方法汇总
- PHP递归遍历多维数组实现无限分类的方法
- PHP 数组遍历方法大全(foreach,list,each)
- PHP数组遍历的方法测试
- PHP 遍历数组的方法汇总
- php实现将二维关联数组转换成字符串的方法详解
- (转载)PHP 遍历数组的方法汇总
- 遍历php数组的几种方法
- php中创建关联数组,以及遍历数组