javascript - How can I remove a key from JSON in PHP? -


this question has answer here:

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

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -