arrays - php foreach sort before results -
i have searched forums not able solve problem:
i have selection displays manufacturers names. working correctly, names not in sort-order.
this code:
<select name="manufacturer_id" id="manufacturer_id" data-inline = "true" style="width: 8.4em;">               <option <?php if(!isset($brand)) { echo 'selected="yes"' ; } ?> ></option>               <?php foreach ($manufacturers $manufacturer) { ?>               <?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>               <option value="<?php echo $manufacturer['manufacturer_id']; ?>" selected="selected"><?php echo $manufacturer['name']; ?></option>               <?php } else { ?>               <option value="<?php echo $manufacturer['manufacturer_id']; ?>"><?php echo $manufacturer['name']; ?></option>               <?php } ?>               <?php } ?>               </select>   is there way sort output? or can point me in right direction?
thanks!
your array 2-d array.... sort works on 1-d array
use
usort(     $manufacturers,     function($a, $b) {         return strcmp($a['name'], $b['name']);     } )      
Comments
Post a Comment