Re: Not Quite: how to build an array

From: Date: Sun, 24 Feb 2002 12:58:39 +0000
Subject: Re: Not Quite: how to build an array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-85989@lists.php.net to get a copy of this message
On Sunday 24 February 2002 04:03, jtjohnston wrote: > I'm splitting mysql entries to build an array of author names called > $authors. > > > As someone already suggested, you could use: > > array_push($authors, explode(";", $mydata->AS)); > > http://ccl.flsh.usherb.ca/db/authors_under_study.php > > It works, but still gets "First argument to array_push() needs to be an > array" and fails before it gets to "print_r($authors)". Am I doing > something wrong here: [snip] What array_push is doing is adding the *whole* array onto the existing array. What you need is to add the *elements* of the array onto the existing array. Try this: $news = mysql_query("select id,AUS from $table"); $authors = array(); while ($mydata = mysql_fetch_object($news)) { echo $mydata->id."|".$mydata->AUS."<hr>\n"; $tmp = explode(";", $mydata->AUS); foreach($tmp as $val) { array_push($authors, $val); } } print_r($authors); -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* Subtlety is the art of saying what you think and getting out of the way before it is understood. */

« previous php.general (#85989) next »