二维数组为什么只输出一个
程序员文章站
2024-02-15 13:31:16
...
2维数组为什么只输出一个?
输出只有
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);
$foodPrices = array(
"vegetable" => array("potato" => 1.00, "onion" => .50),
"fruit" => array("apple" => 2.50, "orange" => 2.00)
);
foreach($foodPrices as $category)
{
foreach($category as $food => $price);
{
$f_price = sprintf("%01.2f", $price);
echo "$food: \$$f_price
";
}
}
?>
输出只有
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);
推荐阅读