如何从foreach循环更改为while循环? [英] How do I change from the foreach loop to the while loop?

查看:140
本文介绍了如何从foreach循环更改为while循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello

Using multi-dimensional arrays, create an array that will store 10 items of stock (can be any item e.g. cars,) with brand name, Number of stock in Store and Quantity Sold

我想使用While循环。我怎么做?请帮忙。





I want to use the While loop. How do I do that? Please help.


<!DOCTYPE html>
<html>
	<head>
		<title>Multi-Dimensional Arrays</title>
		<meta http-equiv="Content-Type" content = "text/html; charset=UTF-8"
	</head>
	<body>
		<?php
		$cars = array
			(
			array("Volvo", 22, 18),
			array("BMW", 15, 13),
			array("Kia", 5, 2),
			array("Land Rover", 17, 15),
			array("Toyota", 16, 18),
			array("Volkswagen", 20, 10),
			array("Audi", 19, 10),
			array("Mercedes Benz", 50, 5),
			array("Mazda", 11, 12),
			array("Ford", 14, 13),
			);		
			
			echo "<table border =\"1\" style='border-collapse: collapse'>";
			echo '<tr><th>Brand name</th><th>Number of Stock in Store</th><th>Quantity Sold</th></tr>';
			
			foreach($cars as $cars)
			{
				echo '<tr>';
				foreach($cars as $key)
				{
					echo '<td>'.$key.'</td>';
				}
				echo '</tr>';
			}
			echo "</table>";
		?>
	</body>
</html>





我尝试过:



我使用了foreach循环它正在工作。



What I have tried:

I have used the foreach loop and it is working.

推荐答案

cars = array

阵列(沃尔沃,22,18),
阵列(宝马,15,13),
阵列(起亚,5,2),
阵列(路虎 ,17,15),
阵列(丰田,16,18),
阵列(大众,20,10),
阵列(奥迪,19,10) ),
阵列(梅赛德斯奔驰,50,5),
阵列(马自达,11,12),
阵列(福特,14,13),
);

echo< table border = \1 \style ='border-collapse:collapse'>;
echo'< tr>< th>品牌名称< / th>< th>商店中的库存数< / th>< th>销售数量< / th>< / tr>';

foreach(
cars = array ( array("Volvo", 22, 18), array("BMW", 15, 13), array("Kia", 5, 2), array("Land Rover", 17, 15), array("Toyota", 16, 18), array("Volkswagen", 20, 10), array("Audi", 19, 10), array("Mercedes Benz", 50, 5), array("Mazda", 11, 12), array("Ford", 14, 13), ); echo "<table border =\"1\" style='border-collapse: collapse'>"; echo '<tr><th>Brand name</th><th>Number of Stock in Store</th><th>Quantity Sold</th></tr>'; foreach(


汽车为


汽车)
{
echo'< tr> ;';
foreach(
cars) { echo '<tr>'; foreach(


这篇关于如何从foreach循环更改为while循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆