ksort krazyness

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

ksort krazyness

Post by shiznatix »

i have array that looks exactally like this

Code: Select all

Array
(
    [4] => Patch
    [5] => Report
    [12] => the
    [15] => of
    [17] => loss
    [6] => is
    [10] => deals
    [1] => Weight
    [13] => different
    [7] => a
    [0] => The
    [16] => weight
    [18] => patches,
    [19] => obviously.
    [2] => Loss
    [3] => Diet
    [14] => types
    [8] => report
    [9] => that
    [11] => with
)
then i run this code

Code: Select all

$ok = ksort($finish);
echo '<pre>';
print_r($ok);
echo '</pre>';
finish is the array above. when i print_r($ok) i get "1" thats it nothing else just the number 1. why?

EDIT: note, this is where $finish comes from

Code: Select all

$finish = $newlinesarr + $arrlines;

//so the whole part looks like
$finish = $newlinesarr + $arrlines;
echo '<pre>';
print_r($finish);
echo '</pre>';
$ok = ksort($finish);
echo '<pre>';
print_r($ok);
echo '</pre>';
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

ksort returns 0 or 1 (false or true) depending on sorting success. Print your array instead for the sorting-results :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

silly rabbit, you cant assign a variable to a ksort!
Post Reply