Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
share|improve this question
    
Read the docs... it returns true on success but the array is altered . us2.php.net/ksort –  Jasper Aug 22 '13 at 15:49

1 Answer 1

up vote 2 down vote accepted

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.