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>

效果图:

效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值