RE: [PHP] foreach not in reach

From: Date: Fri, 22 Feb 2002 08:45:31 +0000
Subject: RE: [PHP] foreach not in reach
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-85830@lists.php.net to get a copy of this message
You didn't supply any information about you foreach() loop, but it works like foreach ($array as $string) print "$element<br>\n"; And explode() returns an array, so I think you need to do it like this: $array = explode(";", $string); array_push($authors, $array); // You could use foreach() here as well Niklas -----Original Message----- From: jtjohnston [mailto:taylorjo@collegesherbrooke.qc.ca] Sent: 22. helmikuuta 2002 8:48 To: php-general@lists.php.net Subject: [PHP] foreach not in reach Question 1: How can I append strings to my authors array? Me thinks this doesn't work :§) ? $authors .= explode(";", $mydata->KW); I'm getting "Invalid argument supplied for foreach()" Question 2: Once I get this working, I want to (a) alphabetise the contents of the array, (b) count repititions, (c) elimintate copies, and create an array I can print with tow things "$author[i]\t$counter[i]", so I end up with something like: Adam 2 Louis 5 John 3 Mary 8 ------------------------------------------------------------------------ $myconnection = mysql_connect($server,$user,$pass); mysql_select_db($db,$myconnection); $news = mysql_query("select KW from $table"); while ($mydata = mysql_fetch_object($news)) { $authors .= explode(";", $mydata->KW); } foreach ($authors as $author) { echo "$author<br>\n"; } ------------------------------------------------------------------------ I'm learning, slowly but surely Martin :) J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#85830) next »