I am trying to sort an associative array according to the key

```
$fruit[2999] = 'apple';
$fruit[332] = 'banana';
$fruit[400] = 'pineapple';
$fruit[87] = 'pear';

$fruit = ksort($fruit);

print_r($fruit);

```

But the output is

> 
> 1
> 
> 
> 

How can I sort the array so that the array will be in this order:

```
$fruit[87] = 'pear';
$fruit[332] = 'banana';
$fruit[400] = 'pineapple';
$fruit[2999] = 'apple';

```