note 47368 modified in function.sort by tularis

From: Date: Sat, 13 Nov 2004 23:27:03 +0000
Subject: note 47368 modified in function.sort by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80476@lists.php.net to get a copy of this message
---[ Editor's Note ]--- You can use array_values() from PHP, which is a lot faster and easier. ---[ End Note ]--- To sort and re-index the array you could use function below: Ex: <? function array_reindex($array) { $quant=count($array); $j=0; $i=0; while ($j < $quant) { if ($array[$i]<>"") { $array_reindex[$j]=$array[$i]; $j++; } $i++; } return($array_reindex); } print_r($users); Return: Array ( [1] => Fred [2] => Erika ) $users=sort($users) Return: Array ( [1] => Erika [2] => Fred ) $users=array_reindex($users); Return: Array ( [0] => Erika [1] => Fred ) ?> --was-- To sort and re-index the array you could use function below: Ex: <? function array_reindex($array) { $quant=count($array); $j=0; $i=0; while ($j < $quant) { if ($array[$i]<>"") { $array_reindex[$j]=$array[$i]; $j++; } $i++; } return($array_reindex); } print_r($users); Return: Array ( [1] => Fred [2] => Erika ) $users=sort($users) Return: Array ( [1] => Erika [2] => Fred ) $users=array_reindex($users); Return: Array ( [0] => Erika [1] => Fred ) ?> http://php.net/manual/en/function.sort.php

« previous php.notes (#80476) next »