gpt4 book ai didi

PHP多数组回显

转载 作者:行者123 更新时间:2023-12-04 00:18:39 25 4
gpt4 key购买 nike

我有一个 php,下面有我如何在 php 中回显。

我想像这样回显

Veg.Pizaa => 
Extra = > Cheese, price 50
Vegetables = > Avocado, price 25

数组在下面

array
(
'Veg.Pizaa' =>
(
array
(
'Extra' =>
(
array
(
'name' => string '25g Cheese' (length=10),
'price' => string '50' (length=2),
'quanty' => int 13,
'Vegetables' =>
),
array
(
'name' => string 'Avocado' (length=7),
'price' => string '25' (length=2),
'quanty' => int 13,
'Nuts' =>
),
array
(
'name' => string 'Almonds' (length=7),
'price' => string '30' (length=2),
'quanty' => int 21
)
)
)
)
)

我尝试过以下代码

foreach($sub as $sub) {
var_dump($sub);
echo "<tr>";
echo "<td><h3 style='font-weight: bolder; color: Maroon; line-height: 10px;'>".$sub[0]['productname']
."</h3></td>";
echo "<td><h3 style='font-weight: bolder; color: Maroon; line-height: 10px;'>".$sub[0]['qty']
."</h3></td>";
echo "</tr>";
}

最佳答案

$array = ...;

foreach( $array as $key => $val )
{
echo $key . " =>\n";

foreach( $val as $key2 => $val2 )
{
echo "\t" . $key2 . ' => ' . $val2['name'] . "\n";
}
}

关于PHP多数组回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12581992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com