如何解析xml并获取节点。
答案 0 :(得分:1)
您可以使用json_decode
解码字符串,删除所有非活动元素的递归函数,最后json_encode
将数组恢复为json字符串
$json = json_decode($data, true);
$json['categoryTree'] = filter_inactive($json['categoryTree']);
echo json_encode($json);
function filter_inactive($data) {
$t = array();
foreach ($data as $child) {
if ($child['is_active'] == '1') {
if (isset($child['children'])) {
$child['children'] = filter_inactive($child['children']);
}
$t[] = $child;
}
}
return $t;
}