php - JSON API data from Array to table


I'm a bit stuck trying to retrieve and display the correct information inside of a table, based on data obtained from an API and symbols which are stored in the database. In short, when I do this:

$div = file_get_contents("$z&types=stats&filter=dividendRate");  
$div = json_decode($div,TRUE);  
foreach($div as $divi => $value) {
echo '<br/>'. $divi.' : '. $value['stats']['dividendRate'];

I get the correct outcome, which is this: FB : 0 GOOGL : 0 AAPL : 2.52

But this only shows it in a simple list, whereas if I want to display this in a table, I can only get it to show the correct symbols but the value for all is 2.52, no matter what. Code:

                echo '<br/>'. $symbol[$x].' : '. $value['stats']['dividendRate']; 

Is it to do with the way I'm referencing this or something? If any additional code from the program is needed then let me know because this is obviously only a part of it. Thanks in advance!




For some reason, this solved the issue:

foreach($div as $divi => $value) {
                echo $value['stats']['dividendRate']; 

People are also looking for solutions to the problem: php - Yii2. Sending data by ajax in GridVIew isn't works


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.