gpt4 book ai didi

php - 如何用 php 读取 json 解码数组?

转载 作者:可可西里 更新时间:2023-11-01 00:50:52 25 4
gpt4 key购买 nike

我有以下数组,但我不知道如何从中获取任何值,这是数组:

Array
(
[0] => stdClass Object
(
[aure] => test
[menu] => stdClass Object
(
[pizza] => stdClass Object
(
[Tomato & Cheese] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)

[onion] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)

)

[Special Dinners] => stdClass Object
(
[Chicken Wings Dinner] => stdClass Object
(
[price] => 15.80
)

[onion] => stdClass Object
(
[small] => 5.50
[large] => 9.75
)

)

)

)

)

您能举个例子说明我怎样才能知道小番茄奶酪披萨的价格吗?

最佳答案

$array[0]->menu->pizza->{"Tomato & Cheese"}->small;

我使用了花括号,因为没有它们我无法获得“番茄和奶酪”(它们有空格)

这会给你所有的披萨

$pizzas = (array) $array[0]->menu->pizza;
foreach($pizzas as $pizzaname => $choices){
echo $pizzaname." (small) is for ".$choices->small."<br />";
echo $pizzaname." (large) is for ".$choices->large."<br />";
}

关于php - 如何用 php 读取 json 解码数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7599402/

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