PHP中foreach嵌套循环输出数组代码?
2012-03-27 · 知道合伙人软件行家
关注
展开全部
以下是编写json数据转换成数组时写foreach嵌套循环输出的代码:
<?php
$json = '[{"a":1,"b":2,"c":3,"d":4,"e":5},{"a":12,"b":22,"c":32,"d":42,"e":52},{"a":13,"b":23,"c":33,"d":43,"e":53}]';
$arr = (array) json_decode($json,true);
foreach($arr as $arrvalue)
{
foreach($arrvalue as $key=>$value)
{
echo "[$key] = $value <br />";
}
}
?>
<?php
$json = '[{"a":1,"b":2,"c":3,"d":4,"e":5},{"a":12,"b":22,"c":32,"d":42,"e":52},{"a":13,"b":23,"c":33,"d":43,"e":53}]';
$arr = (array) json_decode($json,true);
foreach($arr as $arrvalue)
{
foreach($arrvalue as $key=>$value)
{
echo "[$key] = $value <br />";
}
}
?>
展开全部
foreach($arr as $key =>$value){
echo $value //$value是值
echo $key //$key是键值
}
楼下哥们弄错了
echo $value //$value是值
echo $key //$key是键值
}
楼下哥们弄错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
foreach($arr $key->$value){
echo $value
}
echo $value
}
追问
那请问能否告诉我循环中套循环的代码?
追答
你想干嘛啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询