3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $json=<<<EOF [ { "id":23, "uid":"0090000219", "cid":"0090000013", "extension":"201", "secret":"Myojyo42_f", "leader":true, "simultaneous":false, "confbridge_id":17, "created_at":"2015-09-02 12:49:12", "updated_at":"2015-09-02 12:49:12" }, { "id":24, "uid":"0090000221", "cid":"0090000013", "extension":"203", "secret":"Myojyo42_f", "leader":false, "simultaneous":false, "confbridge_id":17, "created_at":"2015-09-02 12:49:12", "updated_at":"2015-09-02 12:49:12" }, { "id":25, "uid":"0090000223", "cid":"0090000013", "extension":"205", "secret":"Myojyo42_f", "leader":true, "simultaneous":false, "confbridge_id":17, "created_at":"2015-09-10 10:16:24", "updated_at":"2015-09-10 10:16:24" } ] EOF; $decoded = json_decode($json, true); foreach($decoded as $key => $val) { if($val['leader'] == 1) { echo count($val['leader']); } //if you want also to count the false then add else in the statement echo count($val['leader']); }
based on kSM6B
Output for 7.2.0
Warning: count(): Parameter must be an array or an object that implements Countable in /in/chlto on line 49 1 Warning: count(): Parameter must be an array or an object that implements Countable in /in/chlto on line 49 1
Output for 5.3.17 - 7.1.10
11