fork download
  1. <?php
  2.  
  3. $object = (object) array(
  4. 'data' => (object) array(
  5. 44 => (object) array(
  6. 'id' => 3.5795,
  7. 'completed' => false,
  8. 'name' => 'Lorem ipsum dolor.',
  9. ),
  10. 45 => (object) array(
  11. 'id' => 3.5796,
  12. 'completed' => false,
  13. 'name' => 'Lorem ipsum dolor.',
  14. ),
  15. 46 => (object) array(
  16. 'id' => 3.5797,
  17. 'completed' => true,
  18. 'name' => 'Lorem ipsum dolor.',
  19. ),
  20. 47 => (object) array(
  21. 'id' => 3.5798,
  22. 'completed' => false,
  23. 'name' => 'Lorem ipsum dolor.',
  24. ),
  25. )
  26. );
  27.  
  28. $countTrue = 0;
  29. $countFalse = 0;
  30.  
  31. foreach($object->data as $item)
  32. {
  33. if($item->completed){
  34. $countTrue ++;
  35. } else {
  36. $countFalse++;
  37. }
  38.  
  39. }
  40.  
  41. echo "Itens como true: " . $countTrue; // 1
  42. echo "<br>";
  43. echo "Itens como false: " . $countFalse; // 3
  44.  
  45.  
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Itens como true: 1<br>Itens como false: 3