Hi all,

Hope you can help - I'm bashing my head against a brick wall ATM.

I have an array (output from print_r):

Array ( [0] => Aberdare Rugby Club [1] => Beehive Inn [2] => Black Lion Hotel [3] => Bute Arms [4] => Gadlys Arms [5] => Glandover Arms [6] => Glosters Arms [7] => Marquis Inn [8] => Morning Star [9] => Pickled Pepper [10] => Boot Hotel (The) [11] => Cambrian Inn (The) [12] => Conway Inn (The) [13] => Mackworth Arms (The) [14] => Whitcombe Hotel [15] => White Lion [16] => Yr Ieuan ap Iago (Wetherspoons) )

and then I sort it with the PHP command 'sort'.

I end up with :

Array ( [0] => Boot Hotel (The) [1] => Cambrian Inn (The) [2] => Conway Inn (The) [3] => Mackworth Arms (The) [4] => Aberdare Rugby Club [5] => Beehive Inn [6] => Black Lion Hotel [7] => Bute Arms [8] => Gadlys Arms [9] => Glandover Arms [10] => Glosters Arms [11] => Marquis Inn [12] => Morning Star [13] => Pickled Pepper [14] => Whitcombe Hotel [15] => White Lion [16] => Yr Ieuan ap Iago (Wetherspoons) )

All the items with (The) in the strings appear above others, but this is not an alphabetical sort - as I was expecting.

Any and all help appreciated - I know it's probably a simple one .... 🙂

Thanks,

ZZ.

    This works OK for me:

    <pre>
    <?php
    $test = array(
       0 => "Aberdare Rugby Club ",
       1 => "Beehive Inn ",
       2 => "Black Lion Hotel ",
       3 => "Bute Arms ",
       4 => "Gadlys Arms ",
       5 => "Glandover Arms ",
       6 => "Glosters Arms ",
       7 => "Marquis Inn ",
       8 => "Morning Star ",
       9 => "Pickled Pepper ",
       10 => "Boot Hotel (The) ",
       11 => "Cambrian Inn (The) ",
       12 => "Conway Inn (The) ",
       13 => "Mackworth Arms (The) ",
       14 => "Whitcombe Hotel ",
       15 => "White Lion ",
       16 => "Yr Ieuan ap Iago (Wetherspoons)"
    );
    print_r($test);
    sort($test);
    print_r($test);
    ?>
    </pre>
    

    You may need to make sure that there are no white-space characters in the beginning of the values, and it might be a good idea to add the optional 2nd arg to sort() using SORT_STRING for it.

      Your code works perfectly ...

      After the sort (without SORT_STRING), it reads (as I would expect):

      Array
      (
      [0] => Aberdare Rugby Club
      [1] => Beehive Inn
      [2] => Black Lion Hotel
      [3] => Boot Hotel (The)
      [4] => Bute Arms
      [5] => Cambrian Inn (The)
      [6] => Conway Inn (The)
      [7] => Gadlys Arms
      [8] => Glandover Arms
      [9] => Glosters Arms
      [10] => Mackworth Arms (The)
      [11] => Marquis Inn
      [12] => Morning Star
      [13] => Pickled Pepper
      [14] => Whitcombe Hotel
      [15] => White Lion
      [16] => Yr Ieuan ap Iago (Wetherspoons)
      )

      I've checked for whitespaces, i.e. :

      ' 'blank
      '\t' tab
      '\n' new line
      '\f' form feed
      '\r' carriage return

      and I can't find them anywhere ..... all the text is pulled from a single-line db entry (from MySQL).

      I can usually work these things out, but I had to post a message, as I'm going mad trying to solve it!

      Thanks for your reply, it is much appreciated.

      Regards,

      ZZ.

        Write a Reply...