Evaluating Strings...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
In php, I have an array called "q".  The elements are:

$q[0] = 2
$q[1] = 4
$q[2] = 5
$q[3] = 3

I'd like to be able to loop through this array via a While loop, and
echo the contents of these array elements back to the screen.

When I try something like:

for($i = 0; $i < 4; $i++) {
   echo $q[i];
   echo eval("$q[i]");
   echo eval("$q[" . i . "]");

I get the "String" instead of the "Contents".  For example, the output
is $q[0] instead of 2, $q[1] instead of 4, etc.

How can I fix this?  Thanks.

Re: Evaluating Strings...

number1.email@gmail.com said the following on 11/12/2005 10:59:
Quoted text here. Click to load it

Use echo $q[$i].


Re: Evaluating Strings...

*** number1.email@gmail.com escribió/wrote (11 Dec 2005 02:59:32 -0800):
Quoted text here. Click to load it

Add this code on top of your script:


It will warn you that you're using an undefined constant called "i".

-+ Álvaro G. Vicario - Burgos, Spain
++ http://bits.demogracia.com es mi sitio para programadores web
+- http://www.demogracia.com es mi web de humor libre de cloro

Site Timeline