Re: Array vs. Scalar Lists

From: Date: Sat, 02 Dec 2000 04:27:55 +0000
Subject: Re: Array vs. Scalar Lists
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28279@lists.php.net to get a copy of this message
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| +----------------------------------------------------------------+

« previous php.general (#28279) next »