Home > php教程 > php手册 > PHP遍历二维数组的代码

PHP遍历二维数组的代码

WBOY
Release: 2016-06-13 12:10:04
Original
999 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";
}
?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template