On Mon, 21 Jun 2004 23:19:58 -0400, Andre Dubuc <[EMAIL PROTECTED]> wrote: > > 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?
foreach($names as $key => $names){ You are reusing the same variable, $names is being overwritten. -- Greg Donald http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php