My json-data is as follows -
[{"name": "ram"}]
What I want is the value of name in a variable e.g., $fname. I have tried -
<?php
$jsondata = '[{"name": "ram"}]';
//$obj = json_decode($jsondata);
$obj = json_decode($jsondata,true);
print_r($obj); // This line outputs as :- Array ( [0] => Array ( [name] => ram ) )
//What I need is value of key
print_r($obj['name']);
foreach ($obj as $k=>$v){
echo $v;
}
?>
But I am unable to get desired output.
print_r($obj);And you will see the structure of your decoded json string. (Wait a minute and you will have tones of vampires here)Array ( [0] => Array ( [name] => ram ) )usingprint_r($obj), but I don't know how to use it, to get value of nameRTMArray ( [0] => Array ( [name] => ram ) )<-- See 2x array! So it's multidimensional. And the first dimension is0thenname