我正在开发一个restfull api,它从firebase数据库获取数据
我成功地检索到了与此完全相同的数据
{
"Admin": {
"-L-ck6q9elghYywXHneg": {
"accepted": false,
"date": "7/12/2017",
"hour": "4:32",
"numberOfPeople": "3",
"tableInfo": ""
}
},
"Guest": {
"-KvJja_r0beLtdoRc29f": {
"accepted": true,
"date": "1/10/2017",
"hour": "0:43",
"numberOfPeople": "",
"tableInfo": ""
}
}
}
现在,我想访问两个记录中的“accepted”字段,而不知道“admin”或“guest”这两个键是如何做到的?
我试过这个
foreach ($users as $user) {
$data[$counter]['accepted'] = $user->accepted;
$counter++;
}
但没有成功
最佳答案
刚刚测试过,与您的数据完美结合:
$users = json_decode($users, true);
foreach ($users as $user) {
$data[$counter]['accepted'] = array_first($user)['accepted'];
$counter++;
}
关于php - 如何从Laravel中的多维json数组获取值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48253490/