note 47368 deleted from function.sort by derick
| From: | derick@php.net | Date: | Wed, 31 Aug 2005 10:41:00 +0000 |
| Subject: | note 47368 deleted from function.sort by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94508@lists.php.net to get a copy of this message | ||
Note Submitter: fred at ocn dot com dot br
----
---[ 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 )
?>