for循环获取对象

I have below PHP forloop, $review is object having values of 'avail_1', 'avail_2', 'avail_2' upto avail_40

$review_array_count = array();

for ($i=1; $i <= 4 ; $i++) {
    if(is_object($review) && $review->avail_.$i == 'yes')
    {
     array_push($review_array_count, '1');
    }
}
echo count($review_array_count);

I am counting how many avail_x having value of 'yes', so i am doing forloop upto 40, then pushing 1 to array and counting array.

How can i use object value as avail_.$i? This does not working.

Thanks,

You just want to count how many avail_x having value of "yes" right?

$count = 0;

foreach (get_object_vars($reviews) as $key => $value) {
    if($value == 'yes'){
        $count++;
    }
}

var_dump($count);

Maybe this can help.

use this:

for ($i=1; $i <= 4 ; $i++) {
$testValObj = 'avail_'.$i;
$mainVal=$review->$testValObj;
    if(is_object($review) && $mainVal == 'yes')
    {
     array_push($review_array_count, '1');
    }
}
echo count($review_array_count);