PHP数组遍历的顺序

1.0k PHP教程 发表评论
经常会有人问我, PHP的数组, 如果用foreach来访问, 遍历的顺序是固定的么? 以什么顺序遍历呢? 比如: <?php $arr['laruence'] = 'huixinchen'; $arr['yahoo'] = 2007; $arr['baidu'] = 2008; foreach ($arr as $key => $val) { //结果是什么? } 又比如: <?php $arr[2] = 'huixinchen'; $arr[1] = 2007; $arr[0] = 2008; foreach…