3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $json = <<<'JSON' [ {"id":1,"name":"Admin","status":1,"created_at":null,"updated_at":null,"pivot":{"user_id":1,"role_id":1}}, {"id":2,"name":"Secretary","status":1,"created_at":null,"updated_at":null,"pivot":{"user_id":1,"role_id":2}} ] JSON; foreach (json_decode($json) as $obj) if ($obj->name) var_dump($obj);
based on Krh8X
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
object(stdClass)#1 (6) { ["id"]=> int(1) ["name"]=> string(5) "Admin" ["status"]=> int(1) ["created_at"]=> NULL ["updated_at"]=> NULL ["pivot"]=> object(stdClass)#2 (2) { ["user_id"]=> int(1) ["role_id"]=> int(1) } } object(stdClass)#3 (6) { ["id"]=> int(2) ["name"]=> string(9) "Secretary" ["status"]=> int(1) ["created_at"]=> NULL ["updated_at"]=> NULL ["pivot"]=> object(stdClass)#4 (2) { ["user_id"]=> int(1) ["role_id"]=> int(2) } }