Re: Array vs. Scalar Lists

From: Date: Fri, 01 Dec 2000 20:14:52 +0000
Subject: Re: Array vs. Scalar Lists
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28277@lists.php.net to get a copy of this message
I don this all the time: print implode ( '', $arrayOfStrings ) ; However, $arrayOfStrings must be a one dimentional array. you could also loop through it. while (list($key, $val) = each($arrayOfStrings)) print $val; -jeremy brand Jeremy Brand :: Sr. Software Engineer :: 408-245-9058 :: jeremy@nirvani.net http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more - - Begin - Advertisement - - - - - - - - - - - - - - - THIS SPACE FOR SALE - - - NO JOKE Get your own Free, Private email at http://www.smackdown.com/ - - - - - - - - - - - - - End - Advertisement - - - - - On Fri, 1 Dec 2000, Anthony Martin wrote: > Date: Fri, 1 Dec 2000 12:12:01 -0800 > From: Anthony Martin <Anthony@TRAMS.com> > To: "'php-general@lists.php.net'" <php-general@lists.php.net> > Subject: [PHP] Array vs. Scalar Lists > > I was wondering if there's a way to pass array keys implicitly to a function > that expects a list of scalars. > > I'm used to perl's method of handling arrays as lists of scalars. If I > wanted to print the concatenated contents of an array, I would just pass the > entire array. > > If I did this with echo, I get the word "Array" (no real surprise). Now, I > understand how to extract all of the values out of the array and pass them > as one string, like: > > echo implode ( '', $arrayOfStrings ) ; > > That would accomplish the task, but not the way I would like. I'm just > using echo as an example. > > 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 > > -- > 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 (#28277) next »