因为Foreach是数组遍历。
你没有2这个Key。所以不会出现你所说的情况
你没有2这个Key。所以不会出现你所说的情况
解决方案 »
- PHP 类型转换问题
- DB Error: extension not found怎么解决
- 问个不知道存不存在的方法函数
- 推荐一本PHP的书吧(急)
- phpmyadmin ZIP 包中有错误: 11
- 求随机产生不同连接
- PHP的fopen函数是不是只能打开DocumentRoot路径内的文件?还是可以打开任何对apache开放读写权限的文件?
- smarty section 循环变量自动生成问题.
- 如何使用<input type="image" src="url" name="name">获得想submit一样的效果,请各位大侠指教一下
- 初学 PHP 请大家推荐好的整合开发工具.谢谢.100 分~哦
- PHP如何访问Access?一定给分~~
- 100分重奖:PHP网站开发,系统架构说明。。。请高手留下QQ号码
/* foreach example 4: multi-dimensional arrays */$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";foreach($a as $v1) {
foreach ($v1 as $v2) {
print "$v2\n";
}
}
ksort那?
(PHP 3, PHP 4 )ksort -- Sort an array by key
Description
int ksort ( array array [, int sort_flags])
Sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays. Example 1. ksort() example$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
This example would display: a = orange
b = banana
c = apple
d = lemon
You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort(). See also asort(), arsort(), krsort(), uksort(), sort(), natsort(), and rsort(). Note: The second parameter was added in PHP 4.
asort
(PHP 3, PHP 4 )asort -- Sort an array and maintain index association
Description
void asort ( array array [, int sort_flags])
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Example 1. asort() example$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
echo "$key = $val\n";
}
This example would display: c = apple
b = banana
d = lemon
a = orange
The fruits have been sorted in alphabetical order, and the index associated with each element has been maintained. You may modify the behavior of the sort using the optional parameter sort_flags, for details see sort(). See also arsort(), rsort(), ksort(), and sort().