I have an array of objects that is being generated from an SQL query within a custom Joomla! 1.5 component:
$query = 'SELECT * FROM #__orders_hearaboutus ORDER BY id';
$this->_hearaboutus = $this->_getList($query);
This generates something like:
Array
(
[0] => stdClass Object
(
[id] => 3
[how_heard] => Our Website
)
[1] => stdClass Object
(
[id] => 4
[how_heard] => Other Website
)
[2] => stdClass Object
(
[id] => 5
[how_heard] => Word of Mouth
)
[3] => stdClass Object
(
[id] => 6
[how_heard] => Other
)
[4] => stdClass Object
(
[id] => 10
[how_heard] => Internet Search Engine
)
[5] => stdClass Object
(
[id] => 11
[how_heard] => Local Newspaper
)
[10] => stdClass Object
(
[id] => 16
[how_heard] => Leaflet by Post
)
[11] => stdClass Object
(
[id] => 18
[how_heard] => Club or Society Newsletter
)
)
This is then generating an HTML select 'Where did you hear about us' drop-down option within an order form.
What I'd like to do is to re-order the list by supplying the IDs in the desired (arbitrary) order, assuming that an array is the best way to do this:
$ordering = array(11,3,4,10,16,5,18,6);
I've found ways of reordering arrays in this way or reordering arrays of objects by keys but I can't work out how to achieve the above?