gpt4 book ai didi

php - 使用 php 循环 json 数组

转载 作者:行者123 更新时间:2023-11-29 11:49:59 27 4
gpt4 key购买 nike

我不知道如何执行以下操作:我以 json 形式检索 mysql 请求,并得到以下结果:

[
{"pid":"1","comment":"La premiere consultation est toujours bizarre..."},
{"pid":"1","comment":"La seconde... c'est jamais mieux !"}
]

现在我正在尝试循环它来生成我的 html 模板。我绝对不是 php 专家,但正在学习:)

感谢您的帮助!

最佳答案

 Thank you Mark, this worked out fine !

$arr = json_decode($json, true);

foreach($arr as $item) { //foreach element in $arr
echo 'Comment: ' . $item['comment'];
}

关于php - 使用 php 循环 json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34257396/

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