Sorting a large text string alphabetically

From: Date: Tue, 22 Jun 2004 03:19:58 +0000
Subject: Sorting a large text string alphabetically
Groups: php.general php.general 
Request: Send a blank email to php-general+get-188789@lists.php.net to get a copy of this message
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(); $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); ?> I assumed this would work, but I get error messages (for every value in the txt array) stating that '$txt' is not an array -- even though it shows up as Array(Joe Blow, Sam Hill, Henry Forget, etc, etc). I'm totally confused here. As you may gather, arrays are not one of my 'strong' points :> Warning: sort() expects parameter 1 to be array, string given in /var/www/html/list.php on line 235 Warning: reset() [function.reset]: Passed variable is not an array or object in /var/www/html/list.php on line 236 Warning: Variable passed to each() is not an array or object in /var/www/html/list.php on line 237 What am I doing wrong? Any help greatly appreciated, Tia, Andre

« previous php.general (#188789) next »