<?php
$arr = array('one'=>'yi', 'two'=>'er', 'three'=>'san');
foreach($arr as $key=>$value)
{
echo $key;
echo '-';
echo $arr[$key];
echo '-';
echo $value;
echo '/';
}
echo '<br>';
foreach($arr as $a)
{
echo $a;
echo '-';
}
?>
one-yi-yi/two-er-er/three-san-san/
yi-er-san-
$switching =
array( 10,
// key = 0
5 => 6,
3 => 7,
'a' => 4,
11, // key =
6 (maximum of integer-indices was 5)
'8' => 2, // key =
8 (integer!)
'02' => 77,
// key = '02'
0 => 12 // the value 10 will be overwritten
by 12
);
本文通过具体示例展示了PHP中如何使用数组进行数据存储与遍历操作,并解释了不同类型的键值对应关系及其输出结果。
291

被折叠的 条评论
为什么被折叠?



