Re: Arrays?
| From: | Nicholas Yim | Date: | Mon, 08 Jan 2007 07:36:23 +0000 |
| Subject: | Re: Arrays? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246734@lists.php.net to get a copy of this message | ||
Hello William Stokes,
1 write a callback function:
[php]
function cmp_forth_value($left,$right){
return $left[4]<$right?-1:($left[4]==$right[4]?0:1);
}
[/php]
2 use the usort function
usort($test,'cmp_forth_value');
Best regards,
======= At 2007-01-08, 14:46:33 you wrote: =======
>Hello,
>
>How to print out the following array $test so that the print order is by the
>fourth[4] key? I need to print out all arrays in $test so that the data is
>ordered by the fourth key in ascending order.
>
>$test =Array (
> [0] => Array (
> [0] => 5
> [1] => 2
> [2] => sika
> [3] => sika.php
> [4] => 1 )
>
> [1] => Array (
> [0] => 8
> [1] =>2
> [2] => Hono
> [3] => hono.php
> [4] => 1 )
>
> [2] => Array (
> [0] => 7
> [1] => 2
> [2] => Kameli
> [3] => kameli.php
> [4] => 4 )
>
> [3] => Array (
> [0] => 6
> [1] => 2
> [2] => koira
> [3] => koira.php
> [4] => 2 )
> )
>
>The way that the data is strored to $test makes it difficult/impossible to
>sort stuff the way I need here while reading it from DB.
>
>Thanks
>-Will
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>
= = = = = = = = = = = = = = = = = = = =
Nicholas Yim
nick.yim@taowap.com
2007-01-08