I have a JSON data in the following format:
{
"pr":"1",
"0":{
"pr":"2",
"rfq":"2"
},
"1":{
"pr":"3",
"rfq":"3"
}
}
I try to decode this JSON and when I access the first data like that:
$decode = json_decode( array(myjsondatas));
echo $decode->pr;
it prints 1
.
But when I try to access array 0
and 1
by using this syntax $decode->[0]->pr;
, it gives me an error:
Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
How can I access the data from array 0
and 1
?
PS: This is how I did to build my json data 'myjsondatas' is not a variable
$arr = array("pr" => '2' , "rfq" => '2');
$arr1 = array("pr" => '3' , "rfq" => '3');
$json = json_encode(array("pr" => '1', $arr, $arr1));