我需要使用 PHP 在 JSON 文件中找到所有 "type": "featured-product" 实例的直接父级。将此父字符串存储在变量中。使用 foreach。
在下面的示例中,变量的值为“1561093167965”和“3465786822452”
我有点失落,谢谢你的帮助!
{
"current": {
"sections": {
"1561093167965": {
"type": "featured-product"
},
"3465786822452": {
"type": "featured-product"
}
}
}
}
foreach ($json['current']['sections'] as $sectionName => $section) {
if ($section['type'] && $section['type'] == 'featured-product') {
$featuredId = $sectionName;
}
}
慕仙森
紫衣仙女
慕沐林林