I have a string (JSON type), i wanted to convert it to PHP Array.
{
"action":"putEntity",
"dataPacket":{
"entity":[
{
"name":"product",
"data":[
{ }
]
}
]
}
}
I did following to do so,
$array = json_decode(json_encode($data), True);
When i do var_dump($array); it displays:
string(1578) "{ "action": "putEntity", "dataPacket": { "entity": [{ "name": "product", "data": [{ }] }] } }"
But when i do, print_r($array); it displays:
{
"action": "putEntity",
"dataPacket":{
"entity":[
{
"name": "product",
"data":[{}]
}
]
}
}
Issue is when i try to print $array['dataPacket'];
it throws error illegal string offset 'dataPacket'
why var_dump is showing it as String? please help.
print_r()
is also saying it's a string. If it were an array, its output would be along the lines ofArray ( [action] => putEntity
etc.