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的數組下標是自動增長的
樓下也是個糊塗蛋,明明自己遍歷的是二維數組,還叫你用一維數組