How can I access the next data? [duplicate] - php

This question already has answers here:
How can I access an array/object?
(6 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I am extracting the name of each element from https://api.coinmarketcap.com/v2/ticker/
I'm doing this as so:
$foo = json_decode($foo, true);
$name = $foo['data'][`1`]['name'];
Which will give me Bitcoin. But how do I move onto the next element? Right now I am physically setting the ['1'] to be 1 which is Bitcoin. And as you can see from the data, its all random numbers to. Its not 1, 2, 3, 4. Its 1, 1027, 52 etc. So Essentially, do I do access the next element?

Use foreach($foo['data']) as $data) then you can get the name by $data['name'] inside the foreach.

Related

extract an mumber from array [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 2 years ago.
In mooodle I create a course via web service the output of array that I print via command print_r is:
[{"id":29,"shortname":"math1"}]
I wanna to extract just 29 of this text via PHP
how can id do it?
to do this you have to decode the array:
<?php
$json_array = ' [{"id":29,"shortname":"math1"}]';
$php_array = json_decode($json_array);
echo $php_array[0]->id;
And you can do a foreach loop if there is more data
Sandbox link

How to add in digits per json objects wih php [duplicate]

This question already has answers here:
How do I `json_encode()` keys from PHP array?
(4 answers)
Closed 4 years ago.
img
How do I add digits per objects?
https://paste.ubuntu.com/p/mSzJnY87KF/
I want to do;
img
what I have to do, I have tried many ways.
tnks for responses
Just need some thing like this
$arr = [];
$arr["1"] = "content 1";
$arr["10"] = "content 2";
echo json_encode($arr);
do not use array_push

How to convert a response to an appropriate form? [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I use Binance API.
The PHP function gets file contents of url:
https://api.binance.com/api/v1/klines?symbol=BTCUSDT&interval=4h&limit=1
I receive such a response:
[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]
How to get the second value? (7635.01000000)
If you want to get the second value use this:
$receivedData = '[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]';
$jsonDecodeData = json_decode($receivedData);
$secondValue = jsonDecodeData[0][1];
echo $secondValue; //7635.01000000

PHP Get Array Value from JSON Not working [duplicate]

This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I want to get the URLS from the JSON below.
$jsonArray = {
"uuid": "signed",
"PreSigned": "{'url': ['www.g.com', 'www.o.com']"}
I tried this $jsonArray -> PreSigned[0]->url
And it didn't work

How do I append a value to an array within an array in PHP? [duplicate]

This question already has answers here:
How to add elements to an empty array in PHP?
(8 answers)
Closed 5 years ago.
Given this PHP array:
$options['systems'] = array(1, 2, 3)
How would I append the value 4 to the $systems array within the $options array?
You could use array_push to push additional items like so:
array_push($options['systems'], 4);
Or the shorthand version:
$options['systems'][] = 4;
You can use php array_push function. Like this. array_push($options['systems'],4);
you can read the detail of array_push from below link.array_push manual

Categories