So, I'm a PHP rookie that could use some tips when it comes to creating a table and sorting this. I'm not looking for a particular fancy solution but rather just get it to work.
JSON data is imported from API to a variable and I want to print product name and price in a list and statically sort this by product name in alphabetical order, instead of order they appear in array. I have created an HTML table which works fine but I am super stuck when it comes to sorting it. Is it possible to do using perhaps some loops rather than involving JavaScript or similar?
I have the imported and decoded JSON data in $product_data and I'm printing the table like this:
<table id="articles">
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php foreach($product_data as $products) { ?>
<tr>
<td><?= $products->product_name; ?></td>
<td><?= $products->price; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
I find plenty of solutions where you can do this sorting dynamically using JS or solutions to sort when connected to a SQL DB, but I just simply want it to show in alphabetical order with no user interaction.
Thanks