How would one go about listing all the values in this api in a html table ordered by their "position24" value?
I know how to call each individual value, but I'm not sure of how to automatically load them in that order.
How would one go about listing all the values in this api in a html table ordered by their "position24" value?
I know how to call each individual value, but I'm not sure of how to automatically load them in that order.
You can call your API, decode the JSON, sort it by this key and return it in a table. The following lines are a base for your solution.
function compare($a, $b) {
return intval($a->position24) - intval($b->position24);
}
$json = file_get_contents('http://www.coincap.io/front');
$data = json_decode($json);
usort($data, 'compare');
// display $data in a table
If you use classes and the compare function (compare
) is in the same class as the usort-function-call you should use:
usort($data, array($this, 'compare'));
UPDATE:
You can echo out your table by calling the attribute like this:
foreach ($data as $row) {
echo $row->long;
echo $row->position24;
}
Because there are so many values, I let it up to, which one you want to display. If you need help how to build a table you find more information here.