php+html數組遍歷 小case

在PHP中,foreach不能大寫 

php:

<?php 
	//數組
$nav_list = [
	'xiaomi'=>[
		'chinese'=>'蝦米',
		'product_name'=>'蝦米1',
		'product_price'=>'1111',
		'thubm'=>'https://i1.mifile.cn/f/i/g/2015/cn-index/qingchun-320.png',
	],
	'hongmi'=>[
		'chinese'=>'紅米',
		'product_name'=>'紅米1',
		'product_price'=>'1222',
		'thubm'=>'https://i1.mifile.cn/f/i/g/2015/cn-index/666320.png',
	],
];

// 獲取小米
// echo $nav_list["xiaomi"];
// 獲取:https://i1.mifile.cn/f/i/g/2015/cn-index/qingchun-320.png
// 
// $thubm = $nav_list["xiaomi"]["thubm"];
// echo "<img src='".$thubm."'/>";  //array

 ?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<table>
		<tr>
			<th>商品類型</th>
			<th>商品名稱</th>
			<th>商品價格</th>
			<th>商品圖片</th>
		</tr>
		<?php 
        // foreach遍歷
		foreach ($nav_list as  $value) {
			echo "<tr>
			<td>{$value['chinese']}</td>
			<td>{$value['product_name']}</td>
			<td>{$value['product_price']}</td>
			<td><img src='".$value['thubm']."'/></td>
		</tr>";
		}

		 ?>
		
	</table>
</body>
</html>

效果圖:

效果

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章