[dev] Sorting arrays with integers
Jan Schneider
jan at horde.org
Wed Aug 10 04:31:12 PDT 2005
Zitat von Xavier Perseguers <pub at perseguers.ch>:
> Hello,
>
> I use Horde_Array::arraySort() to sort items based on a column name in a
> project.
>
> -------
> require 'Horde/Array.php';
>
> $table = array(array('name' => 'c',
> 'val' => '10'),
> array('name' => 'd',
> 'val' => '6'),
> array('name' => 'a',
> 'val' => '20'));
>
> Horde_Array::arraySort($table, 'val');
>
> echo '<pre>'; print_r($table); echo '</pre>';
> -------
>
> gives me values in following order: 10, 20, 6 instead of (human natural)
> 6, 10, 20.
>
> How can I change this?
You would need to use strnatcmp() instead of str_coll() in arraySort().
Jan.
--
Do you need professional PHP or Horde consulting?
http://horde.org/consulting/
More information about the dev
mailing list