Jump to content

[SOLVED] How to sort Array


noobh

Recommended Posts

ok this is the code

 

<?php

$array = array('one'=>'orange','two'=>'banana','three'=>'grapes','four'=>'lemon','five'=>'apple');

sort($array);

foreach($array as $key => $val){

echo $key . "=>" . $val . "<br />";

}

 

This is the output the value are already sorted

 

0=>apple

1=>banana

2=>grapes

3=>lemon

4=>orange

 

But this is the output that i like

 

five=>apple

two=>banana

three=>grapes

four=>lemon

one=>orange

 

the value are sorted and the key are still remain!!

i mean the key of apple is still five and not become 0

 

any idea thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/77288-solved-how-to-sort-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.