Heim  >  Artikel  >  Backend-Entwicklung  >  二维数组为什么只输出一个

二维数组为什么只输出一个

WBOY
WBOYOriginal
2016-06-13 12:59:551601Durchsuche

2维数组为什么只输出一个?

<br />
	<?php<br />
<br />
		$foodPrices = array(<br />
			"vegetable" => array("potato" => 1.00, "onion" => .50),<br />
			"fruit" => array("apple" => 2.50, "orange" => 2.00)<br />
		);<br />
<br />
		foreach($foodPrices as $category)<br />
		{<br />
			foreach($category as $food => $price);<br />
			{<br />
				$f_price = sprintf("%01.2f", $price);<br />
				echo "$food: \$$f_price <br>";<br />
			}<br />
		}<br />
	?><br />


输出只有
onion: $0.50
orange: $2.00 

为什么会少一个
------解决方案--------------------
foreach($foodPrices as $category)
    {
        foreach($category as $food => $price)   //这一行多个分号
        {
            $f_price = sprintf("%01.2f", $price);
            echo "$food: \$$f_price ";
        }
    }
------解决方案--------------------
foreach($category as $food => $price);
这里多了个分号;
------解决方案--------------------
第二个foreach后面有 ; 分号。
ok??
------解决方案--------------------
foreach($category as $food => $price);

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn