Need some help with array sorting
| From: | Will Steffen | Date: | Thu, 12 Sep 2002 11:32:15 +0000 |
| Subject: | Need some help with array sorting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116133@lists.php.net to get a copy of this message | ||
Ahem *tap* *tap* is this thing on?
Hi everyone, my name is Will and I've been addicted to php for 3 months
and 21 days... *grin*
I'm hitting a bit of a brick wall in a current project - the answer is
probably quite simple, but I'm still newish to php and coding in general
so bear with me:
I have a multidim array which looks something like :
$blocks[0] = array("param1"=>"4","param2"=>"some other
param")
$blocks[1] = array("param1"=>"3","param2"=>"some other
param")
$blocks[2] = array("param1"=>"6","param2"=>"some other
param")
And so forth
Fairly straight forward you say, my problem is that elements can be
inserted into the blocks array in no particular order and I need to sort
at the top level using the values in param1 - so my output should be:
$sorted_blocks[0] = array("param1"=>"3","param2"=>"some
other param")
$sorted_blocks[1] = array("param1"=>"4","param2"=>"some
other param")
$sorted_blocks[2] = array("param1"=>"6","param2"=>"some
other param")
I've had a long hard look at the manual and all those obscure array
manipulation goodies (ksort, multisort, etc) and done some hunting on
phpbuilder and the like, but turned up zip - either I'm not
understanding the array functions properly, or this can't be done, or
there's a nifty trick for doing it which I havent figured out?
Ideally I'd like to be populating blocks using an sql query so I could
do an order by or some such upfront, but this world is anything but
ideal.
Any1 got 2c for me?
Thanks in advance
Will