Home >Backend Development >PHP Tutorial >PHP遍历二维数组的代码_php技巧

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

WBOY
WBOYOriginal
2016-05-17 09:19:591028browse

一开始打算用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