* Thus wrote Andre Dubuc:
> I'm trying to sort alphabetically a large text string filled with first and
> last names separated by ", " That would seem to be a simple task, but
> sort($txt) does not seem to work even when $txt is an array.
>
> The code :
>
> <?php
>
> $OK= "Joe Blow, Sam Hill, Henry Forget, etc, etc";
>
> $_SESSION['txt'] = "$OK";
> session_write_close();
Are you really wanting to do this? this is a lot of overhead.
> $txt = $_SESSION['txt'];
>
>
> $names = explode(", ", $txt);
> foreach($names as $key => $names){
>
> sort($names); //line 235
> reset($names); // line 236
> while (list($key, $val) = each($names)) { //line 237
> }
> }
>
> $sorted = implode(", ", $names);
> return($sorted);
Now for the real issue... I'm not sure what all the foreach and
while loops are for but to simply sort your list you need two lines:
$sorted = explode(", ", $txt); // actually is $tosort
sort($sorted); // but its sorted now.
Curt
--
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about. No, sir. Our model is the trapezoid!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php