PHP遍历二维数组的代码_php技巧

WBOY
Release: 2016-05-17 09:19:59
Original
1004 people have browsed it

一开始打算用foreach来历遍,但是发现没有成功,oo不过关,没办法oo写······
研究后决定用for循环,演示代码如下:

复制代码 代码如下:

$blog=array(
array(
"titledata"=>"titleMM",
"bodydata"=>"bodyMM"
),
array(
"titledata"=>"titleGG",
"bodydata"=>"bodyGG"
)
);
//出错
foreach($blog as $b)
{
$b['titledata']="BB";
$b['bodydata']="CC";
}
print_r($blog);
//正确
for($i=0;$i{
$blog[$i]['titledata']="title";
$blog[$i]['bodydata']="body";
}
?>
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!