i have an array that looks like:
array(5) {
["title"]=>
string(22) "http://example.com/288"
["title2"]=>
string(22) "http://example.com/290"
["title3"]=>
string(22) "http://example.com/284"
["title4"]=>
array(2) {
[0]=>
string(22) "http://example.com/275"
[1]=>
string(22) "http://example.com/274"
}
["title5"]=>
array(2) {
[0]=>
string(22) "http://example.com/292"
[1]=>
string(22) "http://example.com/291"
}
}
i want to arsort the arrays which works just fine as long as my value isnt an array in itself. if i arsort($array); it gives this:
array(5) {
["title5"]=>
array(2) {
[0]=>
string(22) "http://example.com/292"
[1]=>
string(22) "http://example.com/291"
}
["title4"]=>
array(2) {
[0]=>
string(22) "http://example.com/275"
[1]=>
string(22) "http://example.com/274"
}
["title2"]=>
string(22) "http://example.com/290"
["title"]=>
string(22) "http://example.com/288"
["title3"]=>
string(22) "http://example.com/284"
}
but i want it to be this:
array(5) {
["title5"]=>
array(2) {
[0]=>
string(22) "http://example.com/292"
[1]=>
string(22) "http://example.com/291"
}
["title2"]=>
string(22) "http://example.com/290"
["title"]=>
string(22) "http://example.com/288"
["title3"]=>
string(22) "http://example.com/284"
["title4"]=>
array(2) {
[0]=>
string(22) "http://example.com/275"
[1]=>
string(22) "http://example.com/274"
}
}
so basically i want to sort array from high to low in the url preserving keys, but when i arsort it puts the values that are arrays at the top of the list regardless of the number in the url
EDIT switched to
uasortas suggested by @xpapadYou should use
uasort()and implement your own comparison function, perhaps: