Nuv Posted March 25, 2011 Share Posted March 25, 2011 I have an array of type Array ( [2] => Array ( [name] => Shelby Baptist Medical Ctr [city] => Alabaster ) [1] => Array ( [name] => Andalusia Regional Hospital [city] => Andalusia ) [0] => Array ( [name] => Long Term Hospital of Anniston [city] => Anniston )) How can sort the keys of an array but there content remains the same so that they are like Array ( [0] => Array ( [name] => Shelby Baptist Medical Ctr [city] => Alabaster ) [1] => Array ( [name] => Andalusia Regional Hospital [city] => Andalusia ) [2] => Array ( [name] => Long Term Hospital of Anniston [city] => Anniston )) Can someone please point me if there is any func. for this Link to comment https://forums.phpfreaks.com/topic/231714-sorting-the-keys-of-an-array/ Share on other sites More sharing options...
Maq Posted March 25, 2011 Share Posted March 25, 2011 To sort by key you would use ksort. Link to comment https://forums.phpfreaks.com/topic/231714-sorting-the-keys-of-an-array/#findComment-1192270 Share on other sites More sharing options...
kenrbnsn Posted March 25, 2011 Share Posted March 25, 2011 Take a look at the function array_values(). ksort() will not give the OP the results that he wants. The OP doesn't really want a sort, but to renumber the primary keys. Ken Link to comment https://forums.phpfreaks.com/topic/231714-sorting-the-keys-of-an-array/#findComment-1192271 Share on other sites More sharing options...
Nuv Posted March 25, 2011 Author Share Posted March 25, 2011 Take a look at the function array_values(). ksort() will not give the OP the results that he wants. The OP doesn't really want a sort, but to renumber the primary keys. Ken Ah array_values() did the trick. I actually saw that function but thought it wont work Link to comment https://forums.phpfreaks.com/topic/231714-sorting-the-keys-of-an-array/#findComment-1192277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.