gpt4 book ai didi

php - 只需要在 JSON 输出中显示数组值

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:06:32 24 4
gpt4 key购买 nike

如何在 php 中只显示 JSON 中的数组值

我正在使用下面的 PHP 代码

echo '{"aaData":'.json_encode($user_details).'}';

它返回低于输出

{"aaData": [
{"id":"31","name":"Elankeeran","email":"ekeeran@yahoo.com","activated":"0","phone":""}
]}

但我需要像下面这样的 JSON 输出

{"aaData": [
{"31","Elankeeran","ekeeran@yahoo.com","0","1234"}
]}

任何人都请帮忙。

最佳答案

$rows = array();
foreach ($user_details as $row) {
$rows[] = array_values((array)$row);
}

echo json_encode(array('aaData'=> $rows));

哪些输出:

{"aaData": [
["31","Elankeeran","test@yahoo.com","0","1234"],
["33","Elan","test@gmail.com","1",""]
]}

关于php - 只需要在 JSON 输出中显示数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8953536/

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