These are my code blocks that I write:
$url = "http://links";
$curl_post_data = array(
"username" => "guest",
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_PORT, 8889);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$curl_response = curl_exec($curl);
curl_close($curl);
$result = $curl_response;
echo $result
What I did try is echo the $result variables and returned as bellow:
{
"price": [
{
"price": "2000",
"origin_name": "JPN",
},
{
"price": "5000",
"origin_name": "USA",
}
]
}
What I want and need to know is how can I get or access the value of each elements which is the price
and origin_name
. I've try to call it with $result[0]['price']['origin_name'][0]
but it doesn't work and returning like below:
Warning: Illegal string offset 'price' in .... on line ...
Warning: Illegal string offset 'origin_name' in .... on line ...
{
I have also try using foreach
function written like bellow:
foreach($result['price'] as $res){
echo $res[0];
}
but it's returning same error message:
Warning: Illegal string offset 'price' in .... on line ...
Warning: Invalid argument supplied for foreach() in .... on line ...