Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ksort() return 1 instead of the sorted array? [duplicate]

php: alphabetically sort multi-dimensional array by its key?

I'm trying to do the exact same thing as the guy in the thread above me. But my ksort($array) seems to return a number 1. What am I doing wrong?

like image 674
user781655 Avatar asked Mar 20 '26 10:03

user781655


1 Answers

Have a look at the manual:

bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] )

You see, ksort returns a boolean value, and directly works on the given array (note the reference sign&). So what you're probably doing is assigning the return value of ksort, like:

$array = ksort($array);

instead of, just:

ksort($array);
like image 99
Yoshi Avatar answered Mar 22 '26 00:03

Yoshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!