Home > Backend Development > PHP Tutorial > foreach 赋值 二维数组解决思路

foreach 赋值 二维数组解决思路

WBOY
Release: 2016-06-13 13:21:31
Original
801 people have browsed it

foreach 赋值 二维数组
foreach ($menu as $k=>$v){
$arr[]['mid'] = $k;
$arr[]['num'] = $v;
}
print_r($arr);
输出:
Array ( [0] => Array ( [mid] =>9999 ) [1] => Array ( [num] => 1 ) ) 
而不是
Array ( [0] => Array ( [mid] =>9999 [num] => 1 ) )??

为什么? 请教啊。 跟我想的不太一样,想不通啊,现在还在线。。。

------解决方案--------------------

PHP code
foreach ($menu as $k=>$v){
     $arr[]=array('mid' =>$k, 'num' =>$v);
}
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

PHP code
foreach ($menu as $k=>$v){
$arr[]=array('mid' =>$k, 'num' =>$v);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template