Reputation: 175
Here's my JSON file:
{"settings":{"name":"pracamojanowa","owner":"kaitek666","id":"AhuJagUjAHu8"}}
I wanted to get the owner
from this array. I have all values exported into an array, but when I try..
$data2['settings']['owner'][$_SESSION['user']];
I get a false
return and an error:
Warning: Illegal string offset 'kaitek666' in C:\xampp\htdocs\test\login\home.php on line 84
That was a bit weird for me, but my print_r
exported array looks a bit unusual as well:
Array ( [settings] => Array ( [name] => pracamojanowa [owner] => kaitek666 [id] => AhuJagUjAHu8 ) )
I need to access the owner
value and the above PHP code to return true
.
Upvotes: 0
Views: 33
Reputation: 22656
$data2['settings']['owner']
Contains the value of the owner.
By doing $data2['settings']['owner'][$_SESSION['user']];
you are attempting to treat the string "kaitek666"
as an array, hence the error.
If you just want the value of the owner $data2['settings']['owner']
will contain what you want. if you want to check to see if the owner matches the user
value in $_SESSION
then do:
if($data2['settings']['owner'] === $_SESSION['user']){
echo "Owner match!";
}else{
echo "Owner does not match!";
}
Upvotes: 3