PHP multidimetional array null check
i have the following value passed to me via a webservice
print_r($result);
stdClass Object (
[array] => Array ( [0] => [1] => )
)
i break it down as follows
$result = $array->return;
foreach ($result as $val2)
{
$temp = $result[$i]->array[0];
$temp .= " - ". $result[$i]->array[1];
}
I want to check if the array is empty (as it is above).开发者_如何学C but i cant access the array via the
$result[$i]->array[0];
as i get Fatal error:
Cannot use object of type stdClass as array
What is the best way to check it?
stdClass is not an array, it is an object. But you access it like an array:
$result[$i]
^^^^
Shouldn't it be something like (without the foreach
):
$array = $result->array;
$temp = vsprintf('%s - %s', $array);
UPDATE:
So to test if it is empty, you can just use
if (empty($result->array[0]))
....
精彩评论