php输出多维数组
㈠ php array多维数组 循环遍历输出 求救!!
<?php
header("content-type:text/html;charset=utf-8");
$data=array (
"province" => "GD", "city" => "GD_ST", "hphm" => "粤DJ1491", "hpzl" => "02","lists"=> array(
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
)
)
);
?>
<html>
<body>
<table border="2">
<tr>
<th>时间</th>
<th>地点</th>
<th>违章事件</th>
<th>违章代码</th>
<th>扣分</th>
<th>罚款</th>
<th>是否处理</th>
</tr>
<?php foreach ($data["lists"] as $k => $v){?>
<tr>
<td><?php echo $v["date"]?></td>
<td><?php echo $v["area"]?></td>
<td><?php echo $v["act"]?></td>
<td><?php echo $v["code"]?></td>
<td><?php echo $v["fen"]?></td>
<td><?php echo $v["money"]?></td>
<td><?php echo $v["handled"]?></td>
</tr>
<?php }?>
</table>
</body>
</html>
㈡ php多维数组怎么用指针输出不用foreach等方法。
如果忽略重复和反向还原,那么直接用array_merge即可
$new_arr = array_merge($arr['1'],$arr[2]);foreach($arr as $v=>$k){
foreach($v as $val=>$key){
$new_arr[$key] = $v
具体操作过程可以多去后盾人平台看着教学视频,这样才会更加易懂。
㈢ php多维数组怎么显示
1 常用的方法有三种
(1)用var_mp方法
(2)用print_r方法
(3)循环遍历
2 一个小示例
$arr=[
[1,2,3],
[4,5,6],
];
法(1)
var_mp($arr);
法(2)
print_r($arr);
法(3)
foreach($arras$row){
foreach($rowas$v)
echo$v.'';
echo'<br/>';
}
3 运行结果
法(1)
㈣ php多维数组
查询出来的数组就是
$a=array(array(1,"苹果",1,"5元"),array(1,"苹果",1,"5元"),array(1,"苹果",1,"5元"));
$b=array(array(1,"白菜",2,"3元"),array(1,"白菜",2,"3元"));
分别查询 $a 和 $b 后,用 $data = array('水果'=>$a,'蔬菜'=>$b) 就可以实现
㈤ php如何输出多维数组
foreach
字数够没。
㈥ PHP如何将SQL查询结果转为多维数组,并按查询行输出
因为是循环取的,你在循环外声明一个空数组,在循环内,将结果集交给这个数组就行了,比如空数组时$arr=array,给数据的时候$arr[ ]=一行结果。php的数组下标是自动增长的
楼下也是个糊涂蛋,明明自己遍历的是二维数组,还叫你用一维数组