0

Im trying to get some data into a string from an API..

<?php
 // create curl resource 
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, "https://api.feathercoin.com/?output=usd"); 

        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $result = curl_exec($ch); 


        // Will dump a beauty json :3
        var_dump(json_decode($result, true));
        // close curl resource to free up system resources 
        curl_close($ch);  
?>

The above gives me: array(1) { ["usd"]=> float(1.210935) }

Now all I need to do is get the 1.210935 into a string of $coinvalue. Can anyone help me do this?!!

Thank you Jason

1
  • json_decode returns a PHP data structure. access it like you would any OTHER php structure, e.g. an array. Commented Nov 29, 2013 at 19:31

1 Answer 1

1
$result = json_decode($result, true);
$coinvalue = (string) $result["usd"];
Sign up to request clarification or add additional context in comments.

3 Comments

Can u help me with one more array?
{"ticker":{"high":43.99,"low":28.6,"avg":36.295,"vol":34514947.05611,"vol_cur":924541.02434,"last":34,"buy":34.006802,"sell":34.000002,"updated":1385755495,"server_time":1385755497}} - It seems this is two arrays? How would I get the value for "buy" out?
us1.php.net/manual/en/language.types.array.php Example #6 should help you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.