javascript - How can I remove a key from JSON in PHP? -
this question has answer here:
- how extract data json php? 2 answers
- how filter array condition 7 answers
how can remove key "src" json if found in array?
$json = '[{"label":"360","file":"http://aaa","src":"http://aaa"}, {"label":"480","file":"http://bbb","src":"http://bbb"}, {"label":"720","file":"http://ccc","src":"http://ccc"}, {"label":"1080","file":"http://ddd","src":"http://ddd"}]'; the desired end result this:
$json = '[{"label":"360","file":"http://aaa"}, {"label":"480","file":"http://bbb"}, {"label":"720","file":"http://ccc"}, {"label":"1080","file":"http://ddd"}]';
well assuming json correct (the above isn't it's missing [] around it), corrected below.
$json = '[{"label":"360","file":"http://aaa","src":"http://aaa"},{"label":"480","file":"http://bbb","src":"http://bbb"},{"label":"720","file":"http://ccc","src":"http://ccc"},{"label":"1080","file":"http://ddd","src":"http://ddd"}]'; $decoded = json_decode($json, true); foreach($decoded $id => $row) { unset($row[$id]['src']); } $json = json_encode($decoded);
Comments
Post a Comment