Re: Arrays?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx
2007-01-08

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux