【发布时间】:2011-06-13 03:04:02
【问题描述】:
【问题讨论】:
-
"我不是 php 专家" 这就是手册存在的原因...
-
有什么东西阻止你运行代码?
【问题讨论】:
$k 是$v 值存储在数组中的索引号。 $k 可以是数组的关联索引:
$array['name'] = 'shakti';
$array['age'] = '24';
foreach ($array as $k=>$v)
{
$k points to the 'name' on first iteration and in the second iteration it points to age.
$v points to 'shakti' on first iteration and in the second iteration it will be 24.
}
【讨论】:
这意味着对于可遍历变量$ex 中的每个键值对,键被分配给$k,值被分配给$v。换句话说:
$ex = array("1" => "one","2" => "two", "3" => "three");
foreach($ex as $k=>$v) {
echo "$k : $v \n";
}
输出:
1 : one
2 : two
3 : three
【讨论】:
你正在循环一个数组。数组具有键(数字,或者当您有关联数组时可以是字符串)和“属于”这些键的值。
您的 $k 是键,$v 是值,并且您正在使用 foreach 遍历每个单独的对。
【讨论】: