0

How can I take string(5) from a nested array working with json in php, I have the following code:

$results = json_decode($response, TRUE);
var_dump($results);

and the output is:

array(8) { ["name"]=> string(9) "Remaining" ["count"]=> int(1) ["frequency"]=> string(8) "realtime"
["version"]=> int(2) ["newdata"]=> bool(false) ["lastrunstatus"]=> string(7) "success" ["lastsuccess"]=>
string(39) "Sat Apr 12 2014 01:04:30 GMT+0000 (UTC)" ["results"]=> array(1) { ["Calories"]=> array(1) {
[0]=> array(1) { ["calorias"]=> string(5) "2,860" } } } }

I need to take the "2,860" so I can encode it again in another array and echo it. First time using PHP, I'm more used to python. Please help (:

1 Answer 1

3

The following code should serve your purpose:

$value = $results["results"]["Calories"][0]["calorias"];

Of course you may use any variable name of your choice instead of $value.

Sign up to request clarification or add additional context in comments.

Comments

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.