Sau*_*aul 15
这意味着对于可遍历变量中的每个键值对$ex,键都被赋值给$k并赋值$v.换一种说法:
$ex = array("1" => "one","2" => "two", "3" => "three");
foreach($ex as $k=>$v) {
echo "$k : $v \n";
}
Run Code Online (Sandbox Code Playgroud)
输出:
1 : one
2 : two
3 : three
Run Code Online (Sandbox Code Playgroud)
$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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17431 次 |
| 最近记录: |