-1

following is my code for php curl where i get values of currency conversion.

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://free.currencyconverterapi.com/api/v5/convert?q=USD_PKR&compact=y" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
$json = json_decode($response, true);
print_r($json);

it gives me result

Array ( [USD_PKR] => Array ( [val] => 131.1098 ) )

I want to put 131.1098 into a variable where I will update a sql table query. Kindly advice

3
  • 1
    RTM: php.net/manual/en/language.types.array.php Commented Oct 11, 2018 at 19:39
  • 1
    You know how to use curl, know json_decode, but can't access values of a simple array? Commented Oct 11, 2018 at 19:40
  • man these scripts are taken from different resources... if i show you the final code which i have made... you will understand my skills... Commented Oct 11, 2018 at 20:12

1 Answer 1

0
$number = $json['USD_PKR']['val'];
Sign up to request clarification or add additional context in comments.

3 Comments

This gave me right result...
A big thanks to sietse85.. thanks
can you accept the answer ;) i also wonder which one downvoted it lol

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.