'Print distinct values from a column with php
I want to print in a table some of the subjects from a database table. I have a function that sorts them by class and I have this code fragment to identify, for example, 'math':
<?php foreach ($subjects as $sub):
if (stripos($sub['subject'], 'math') !== false): ?>
<td><?php echo $sub['subject']; ?></td>
<?php endif ?>
<?php endforeach ?>
So, if there is a subject 'math' in this class, it will be printed. But if I have another subject which contains 'math', it continues to print it on next column. Obviously, every subject has a unique id and I guess this can be somehow used to identify every subject, but I cant figure it out how.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
