I’m using sort to sort an array alphabetically that’s done like this:
$Consumer[] = "Norman";
$Consumer[] = "Food";
$Consumer[] = "Clothes";
$Consumer[] = "Chips";
But when I use this code to output the array, it won’t work.
$cat = sort($Consumer);
foreach ($cat as $value)
{
echo '<option value="'.$value.'">'.$value.'</option>';
}
It works if I remove the sort. What am I doing wrong here and how do I set this right?
sort acts by reference
As indicated in the docs sort acts by reference and returns a boolean
so
$catis a boolean (true or false).The following is a working example of your code: