tags:

views:

95

answers:

4

I'm looking at http://www.php.net/manual/en/array.sorting.php as a reference. I'm trying to sort the $_POST by the keys. This is what I am trying, but it only prints "1". What else needs to happen, or what is missing? Thank.

<?php
    $data = krsort($_POST);
    print_r( $data );
?>
+3  A: 

krsort returns a boolean - TRUE on success, FALSE on failure. Try print_r($_POST); and see what comes out - the array should be sorted!

thetaiko
+2  A: 

The return value of ksort() is true or value, whether or not the sorting was successful, instead of the sorted array.

Try:

<?php
    krsort($_POST);
    print_r( $_POST );
?>
Chacha102
Thank you very Much!
roydukkey
+2  A: 

The array sorting functions typically modify the array in-place - so you'd want to print_r($_POST) instead. The reason you're getting 1 right now as your output is because the return value from the sort functions is a status code indicating whether or not the array was able to be sorted properly - 1 indicates success.

Amber