Q:

can't access object in array PHP

Have tried every variation I can think of to access an object property in an array. I'm getting some data back form an API which i'm storing in a variable called $userTokenValid:
$userTokenValid = [{"authTokenValid":1}];

i'm then trying to access the authTokenValid property like so:
echo json_decode($userTokenValid[0]->authTokenValid);

I appreciate this might be quite basic but can't spot where I have gone wrong.

A:

$userTokenValid isn't valid php. However [{"authTokenValid":1}] is a valid json string.
$userTokenValid = '[{"authTokenValid":1}]';

you can decode it with
$json = json_decode($userTokenValid);

finally
echo $json[0]->authTokenValid;

