- print_r: documentation ( source)
- asort: documentation ( source)
- key: documentation ( source)
- next: documentation ( source)
<?php
$arr = [7, 3, 5, 4];
asort($arr);
$temp = [];
$count = 1;
$key = key($arr);
while (next($arr)) {
$temp[$key] = key($arr);
$key = key($arr);
$count++;
}
$temp[$key] = -1;
print_r($temp);
$result = [];
for ($i = 0; $i < $count; $i++) {
$result[] = $temp[$i];
}
print_r($result);