PHP重新编号数组但保留序列

I have an array like this:

array(13,4,7,1,16);

I want to recount the array, but I want to keep the sequence, like this:

array(4,2,3,1,5);

How can I do this?

if you want to get the index of the array with reference to the sorted values

Try this

 $numbers = array(13,4,7,1,16);
$numberscopy = $numbers;
sort($numberscopy);
$final = array();
//echo array_search(13, $numbers);
for($a=0 ; $a<count($numberscopy );$a++){

$final[] = array_search($numberscopy[$a], $numbers) + 1;
}
var_dump($final);

If you are trying to sort the array, keeping the keys in the same order as the values, the PHP asort() function does that.

If you want to keep the original array but get the keys in sort order, then you can use something like:

$arr = array(13,4,7,1,16);
asort($arr);
$keys = array_keys($arr);

Then $keys has the keys from the original array sorted in the order of the original values, e.g. $keys = array(4,2,3,1,5);