Re: array output as a variable?

From: Date: Thu, 12 Apr 2001 06:39:12 +0000
Subject: Re: array output as a variable?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-48251@lists.php.net to get a copy of this message
Hi midget2000x, @ 2:13:10 AM on 4/12/01, midget2000x wrote: ... > Obviously the code below is impossible, but illustrates what I want to do: > //declare the array > $info_request = array (1 => > "firstname","lastname","email","howfound","optin","comments","request_type","request_bucket","date"); > > //output the array loop results to a variable > $array_results = foreach ($info_request As $value) { print "$value,"; } > //place the output variable into an SQL call (therefore making it > dynamic): > INSERT INTO $tablename ($array_results) How about: <?php $info = array ( "firstname","lastname","email","howfound","optin", "comments","request_type","request_bucket","date" ); while(list($idx,$value) = each($info)) { $results .= ($idx == (sizeof($info) - 1) ? "'$value'" : "'$value',"); } /* INSERT INTO foo ($results) */ ?> -Brian -- PGP is spoken here: 0xE4D0C7C8 Please do not carbon copy me on list replies.

« previous php.general (#48251) next »