您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP遍历关联数组的几种方法_PHP教程

2024/5/27 11:12:49发布18次查看
在php中数组分为两类: 数字索引数组和关联数组。其中数字索引数组和c语言中的数组一样,下标是为0,1,2…而关联数组下标可能是任意类型,与其它语言中的hash,map等结构相似。
下面介绍php中遍历关联数组的三种方法:
foreach 'good', 'swimming' => 'very well', 'running' => 'not good' ); foreach ($sports as $key => $value) { echo $key.: .$value.
;}?>
程序运行结果:
football: goodswimming: very wellrunning: not good


each 'good', 'swimming' => 'very well', 'running' => 'not good' ); while ($elem = each($sports)) { echo $elem['key'].: .$elem['value'].
;}?>
程序运行结果:
football: goodswimming: very wellrunning: not good


list & each 'good', 'swimming' => 'very well', 'running' => 'not good' ); while (list($key, $value) = each($sports)) { echo $key.: .$value.
;}?>
程序运行结果:
football: goodswimming: very wellrunning: not good


http://www.bkjia.com/phpjc/752443.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/752443.htmltecharticle在php中数组分为两类: 数字索引数组和关联数组。其中数字索引数组和c语言中的数组一样,下标是为0,1,2…而关联数组下标可能是任意...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product