Hey,

I have looked for ages for something so simple, yet I always find complicated answers :mad:

I have an array like 'admin', 'rich', 'alex'
which I have listed in a drop down box, but I want it sorted alphabetically so the results would be:
<select>
<option>admin</option>
<option>alex</option>
<option>rich</option>
</select>

Any simple answers would be greatly appreciated...

Thanks
Mark Baker

    This is my code for testing purposes
    $xusermatch = eregi_replace("::", ":', ':", $users);
    $xusermatch = eregi_replace(":", "':", $xusermatch);
    $xusermatch = eregi_replace(":$", ":'", $xusermatch);
    echo"$xusermatch<br>";
    sort($xusermatch);
    echo"$xusermatch";

    This is the result of the above code:
    ':admin:', ':rich:', ':alex:'

    Warning: Wrong datatype in sort() call in /home/sites/site10/web/item.php on line 97
    ':admin:', ':rich:', ':alex:'

    Any-one else come across this??

      Hi,

      $xusermatch isn't an array at all. You might need to do the following:

      $xusermatch = eregi_replace("::", ":', ':", $users); 
      $xusermatch = eregi_replace("^:", "':", $xusermatch); 
      $xusermatch = eregi_replace(":$", ":'", $xusermatch); 
      echo"$xusermatch<br>"; 
      $arrUsermatch = explode(",",$xusermatch);
      sort($arrUsermatch); 
      echo implode(",",$arrUsermatch);
      reset($arrUsermatch);
      // now populate the select
      

      Use the array to populate the options of your select.

        This is bizarre :eek:

        This is what happens with the above code:

        'admin', 'rich', 'alex'
        'alex', 'rich', 'admin'

        The top line is the original order, and the bottom is after it has sorted it, although all its done is turned it backwards

        Help please

          try this

          $arrUsermatch = explode(",",$xusermatch);

          print_r($arrUsermatch);

          sort($arrUsermatch);
          reset($arrUsermatch);

          print_r($arrUsermatch);

          does it give the same output ??

          reg
          kevin

            Hey,

            This gives the output:

            'admin', 'rich', 'alex'
            Array ( [0] => 'admin' [1] => 'rich' [2] => 'alex' ) Array ( [0] => 'alex' [1] => 'rich' [2] => 'admin' )

              Hi,

              there are three problems:

              1) the ":', ':" with the space after the , will have an affect on the sort because the space will be included in the sort
              2) same for the '
              3) same for the :

              This should work:

              <?PHP
              $users=":alex::blubb::alex2:";
              $xusermatch = str_replace("::",",",$users);
              $xusermatch = str_replace(":","",$xusermatch);
              //$xusermatch = eregi_replace("::", ":,:", $users); 
              //$xusermatch = eregi_replace("^:", "", $xusermatch); 
              //$xusermatch = eregi_replace(":$", "", $xusermatch); 
              //$xusermatch = str_replace(":","",$xusermatch);
              echo"$xusermatch<br>"; 
              $arrUsermatch = explode(",",$xusermatch);
              asort($arrUsermatch); 
              reset($arrUsermatch);
              echo implode(",",$arrUsermatch);
              
              // now populate the select
              ?>
              
                Write a Reply...