[dev] Sorting arrays with integers
Xavier Perseguers
pub at perseguers.ch
Wed Aug 10 04:54:27 PDT 2005
>>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().
Yes, that's it. Thanks.
Xavier Perseguers
More information about the dev
mailing list