PHP If语句 - >

Here is my problem

CODE:

$response = json_decode($data);

$arr = (array) $response;

if(is_array($arr['reviews'])){

foreach($arr['reviews'] as $review){

if ($review->rating == "0") {echo "<div class="0stars"></div>
";}

} 

It throws me an error when it gets to the if portions

Parse error: syntax error, unexpected '0' (T_LNUMBER), expecting ',' or ';' in /home....

I've tried:

$reviewstar = $review->rating;
if ($reviewstar == "0") {echo "<div class="0stars"></div>
";}

and many other options....

How can I do that? do I need to array again?

Thanks!

The quotes in this line are broken:

if ($review->rating == "0") {echo "<div class="0stars"></div>
";}

Change it to:

if ($review->rating == "0") {echo "<div class=\"0stars\"></div>
";}

You are trying to cast to array, but then use object type access here:

$review->rating

If you want to work with an array of objects the don't cast to an array (or force array in json_decode as has been suggested.

The most important thing is to understand the structure of the JSON string and how this will behave when decoded into an object/array.

Also it looks like you might not have closed out your curly braces from first if statement.