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

PHP遍历二维数组的代码

WBOY
WBOYOriginal
2016-06-13 12:10:04996browse

一开始打算用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";
}
?>

Statement:
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