Question

I have a problem with ksort, it is print_r'ing 1 instead of the array.

Here is my array:

Array(

[1] => Array
    (
        [time] => 08:30 am
        [time_id] => 48451
    )

[0] => Array
    (
        [time] => 09:00 am
        [time_id] => 48452
    )

[2] => Array
    (
        [time] => 09:30 am
        [time_id] => 48453
    )

)

And ksort($array) is vardumping bool(true). Why is it not sorting my array appropriately?

echo '<pre>';
print_r($array);
$array = ksort($array);
var_dump($array);
Was it helpful?

Solution

Why is it not sorting my array appropriately?

ksort() works on the array directly and returns a bool - returning true on success and false otherwise.

print_r() outputs 1 (i.e. true) because ksort() successfully sorted the array.

Don't reassign $array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top