<?php
$object = (object
) array( 'data' => (object
) array( 'id' => 3.5795,
'completed' => false,
'name' => 'Lorem ipsum dolor.',
),
'id' => 3.5796,
'completed' => false,
'name' => 'Lorem ipsum dolor.',
),
'id' => 3.5797,
'completed' => true,
'name' => 'Lorem ipsum dolor.',
),
'id' => 3.5798,
'completed' => false,
'name' => 'Lorem ipsum dolor.',
),
)
);
$countTrue = 0;
$countFalse = 0;
foreach($object->data as $item)
{
if($item->completed){
$countTrue ++;
} else {
$countFalse++;
}
}
echo "Itens como true: " . $countTrue; // 1
echo "<br>";
echo "Itens como false: " . $countFalse; // 3
PD9waHAKCiRvYmplY3QgPSAob2JqZWN0KSBhcnJheSgKICAgICdkYXRhJyA9PiAob2JqZWN0KSBhcnJheSgKICAgICAgICA0NCA9PiAob2JqZWN0KSBhcnJheSgKICAgICAgICAgICAnaWQnID0+IDMuNTc5NSwKICAgICAgICAgICAnY29tcGxldGVkJyA9PiBmYWxzZSwKICAgICAgICAgICAnbmFtZScgPT4gJ0xvcmVtIGlwc3VtIGRvbG9yLicsCiAgICAgICAgKSwKICAgICAgICA0NSA9PiAob2JqZWN0KSBhcnJheSgKICAgICAgICAgICAnaWQnID0+IDMuNTc5NiwKICAgICAgICAgICAnY29tcGxldGVkJyA9PiBmYWxzZSwKICAgICAgICAgICAnbmFtZScgPT4gJ0xvcmVtIGlwc3VtIGRvbG9yLicsCiAgICAgICAgKSwKICAgICAgICA0NiA9PiAob2JqZWN0KSBhcnJheSgKICAgICAgICAgICAnaWQnID0+IDMuNTc5NywKICAgICAgICAgICAnY29tcGxldGVkJyA9PiB0cnVlLAogICAgICAgICAgICduYW1lJyA9PiAnTG9yZW0gaXBzdW0gZG9sb3IuJywKICAgICAgICApLAogICAgICAgIDQ3ID0+IChvYmplY3QpIGFycmF5KAogICAgICAgICAgICdpZCcgPT4gMy41Nzk4LAogICAgICAgICAgICdjb21wbGV0ZWQnID0+IGZhbHNlLAogICAgICAgICAgICduYW1lJyA9PiAnTG9yZW0gaXBzdW0gZG9sb3IuJywKICAgICAgICApLAogICAgKQopOwoKJGNvdW50VHJ1ZSA9IDA7CiRjb3VudEZhbHNlID0gMDsKCmZvcmVhY2goJG9iamVjdC0+ZGF0YSBhcyAkaXRlbSkKewogICAgaWYoJGl0ZW0tPmNvbXBsZXRlZCl7CiAgICAgICAgJGNvdW50VHJ1ZSArKzsKICAgIH0gZWxzZSB7CiAgICAgICAgJGNvdW50RmFsc2UrKzsKICAgIH0KCn0KCmVjaG8gIkl0ZW5zIGNvbW8gdHJ1ZTogIiAuICRjb3VudFRydWU7IC8vIDEKZWNobyAiPGJyPiI7CmVjaG8gIkl0ZW5zIGNvbW8gZmFsc2U6ICIgLiAkY291bnRGYWxzZTsgLy8gMwoK