Pogledajte određenu poruku
Staro 18. 11. 2008.   #1
cvele
Banned
Knowledge base
 
Avatar cvele
 
Datum učlanjenja: 01.07.2005
Poruke: 1.598
Hvala: 206
140 "Hvala" u 89 poruka
cvele ima spektakularnu aurucvele ima spektakularnu auru
Default Sort multi dimensional array

PHP kôd:
/*
 * Sort multi dimensional array
 *
 * @author Vladimir Cvetic < vladimir[ at ]ferdinand.rs >
 * @param $a array Array you wish to sort
 * @param $index mixed Value of the key by wich you wish to sort
 * @param $order string Sort direction
 * @param $natsort bool Natural sorting true or false
 * @param $case_sensitive bool Case sensitive true or false
 */
function Sort2dArray ($a$index$order='asc'$natsort=false$case_sensitive=false)
{
    if(
is_array($a) && sizeof($a)>0)
    {
        foreach(
array_keys($a) as $key)
            
$temp[$key]=$a[$key][$index];
        if(!
$natsort)
            (
$order=='asc')? asort($temp) : arsort($temp);
        else
        {
            (
$case_sensitive)? natsort($temp) : natcasesort($temp);
            if(
$order!='asc')
                
$temp=array_reverse($temp,true);
        }
        foreach(
array_keys($temp) as $key)
            (
is_numeric($key))? $sorted[]=$a[$key] : $sorted[$key]=$a[$key];
        return 
$sorted;
    }
    return 
$a;

Original: http://www.hazaah.com/programming/so...nsional-array/
cvele je offline   Odgovorite uz citat