RE: [PHP] Array vs. Scalar Lists

From: Date: Fri, 01 Dec 2000 20:56:02 +0000
Subject: RE: [PHP] Array vs. Scalar Lists
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28284@lists.php.net to get a copy of this message
Whats wrong with somthing like ibase_execute( $prep, implode('',$data)); ? James -----Original Message----- From: Anthony Martin [mailto:Anthony@TRAMS.com] Sent: 01 December 2000 20:41 To: 'Lars Torben Wilson' Cc: 'php-general@lists.php.net' Subject: RE: [PHP] Array vs. Scalar Lists Ok, like I said, I'm using echo as an example. What I'm really trying to do is a little more complicated: $data = Array ( 'c1f2g3h4j5r', 'AC', ) ; $stmt = 'SELECT * FROM PROFILE WHERE SESSION = ? AND STATUS = ? ;' ; $prep = ibase_prepare ( $dbh, $stmt ) ; $result = ibase_execute ( $prep, $data[0], $data[1] ) ; I want to avoid having to pass each value of the array to ibase_execute. I would much rather do: $result = ibase_execute( $prep, $data ) ; But this function wants to see two values. It doesn't take into account that it's been given an array with two values in it. So if I want a programmatic solution, I have to use my eval() insanity (or is that evil insanity like Microsoft's spell check keeps telling me it is). Anthony -----Original Message----- From: Lars Torben Wilson [mailto:torben@pinc.com] Sent: Friday, December 01, 2000 8:28 PM To: Anthony Martin Cc: 'php-general@lists.php.net' Subject: Re: [PHP] Array vs. Scalar Lists Anthony Martin writes: [trim] > So, I want to _simulate_ the following: > > echo $arrayOfStrings[0], $arrayOfStrings[1], $arrayOfStrings[2] ; > > The problem with the above statement is that if $arrayOfStrings[3] exists, > it's not printed. > > I found a way to do it with eval(), and it works to my satisfaction because > I'm not actually imploding the values, just the keys of the array in the > proper syntax: > > $stmt = 'echo ' ; > foreach ( $arrayOfStrings as $key => $val ) { > if ( next ( $strings ) ) { > $stmt .= "\$arrayOfStrings[$key], " ; > } else { > $stmt .= "\$arrayOfStrings[$key] ;" ; > } > } > eval ( $stmt ) ; > > I'm sure I could have used another function like array_keys(), but it helps > to get the keys one at a time so I can add the correct syntax. But is there > a way to do this without eval()? > > > Anthony Why don't you like implode()? You're doing an insane amount of work to accomplish pretty much the same thing...and even so, the above would be better written as $stmt = 'echo ' . implode(', ', $arrayofstrings) . ";"; eval($stmt); What added value are you getting from the eval() here? -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#28284) next »