too long

I'm trying to do a count of those messages that have not been read which has a value of 0. I'm getting the error that its trying to get a property of a non object and I understand why but not sure how to do a count of the individual pm messages.

<?php echo count($personal_messages->message_read == 0); ?>


Array
(
    [0] => stdClass Object
    (
        [id] => 2
        [subject] => Test 2
        [date_sent] => 2012-03-05 00:00:00
        [first_name] => Jeffrey
        [last_name] => Davidson
        [message_read] => 1
    )

    [1] => stdClass Object
    (
        [id] => 1
        [subject] => Testing
        [date_sent] => 2012-03-04 00:00:00
        [first_name] => Jeffrey
        [last_name] => Davidson
        [message_read] => 0
    )

 )

Count expects an ARRAY to be passed in, you're passing in a single boolean value: the result of your equality comparison. For this to work, you'll have to count manually by looping over the array. Since you're getting the 'property of a non-object' as well, that means $personal_messages is not actually an object.

You don't show how you populate that varaible, but the code would end up looking something like:

$count = 0;
foreach($whatever as $subobj) {
    $count += ($subobj->message_read == 1);
}