473,490 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Evaluating Strings...

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.

Dec 11 '05 #1
2 978
nu***********@gmail.com said the following on 11/12/2005 10:59:
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.


Use echo $q[$i].
--
Oli
Dec 11 '05 #2
*** nu***********@gmail.com escribió/wrote (11 Dec 2005 02:59:32 -0800):
for($i = 0; $i < 4; $i++) {
echo $q[i];


Add this code on top of your script:

error_reporting(E_ALL);

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
--
Dec 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1806
by: Michael L. Labbe | last post by:
Hello. I'm an experienced programmer who is evaluating learning Python if it is applicable to a few projects. The programs I am going to list are production software - they are not throwaway toy...
25
2943
by: Jason | last post by:
Hi, below is example code which demonstrates a problem I have encountered. When passing a number to a function I compare it with a string's size and then take certain actions, unfortunately during...
10
1684
by: Jason Heyes | last post by:
Are the side effects of evaluating expr1 resolved before expr2 is evaluated? if (expr1 && expr2) Thanks.
2
2306
by: Sanjeev | last post by:
Hi, I am evaluating Lumigent's Entegra for doing security and business audit of some of the critical database(s) in the company I work for. I would like to know what has been your experience in...
0
3051
by: Boulent Mustafa | last post by:
Using Microsoft Access 2000, I am defining a bunch of fields all with default values. The reason for this is that I have 5 text fields, each of which can have 5 permutations depending on the...
10
6387
by: John A Grandy | last post by:
What's the proper way to write a validation regex so that all leading and trailing spaces are trimmed before evaluation ? Thanks.
4
1456
by: louise raisbeck | last post by:
Hi there, I have created a vb server function which i want to evaluate when a server control button is clicked (only!) however it is evaluating the code on load even though i havent put it into the...
3
2142
by: Ashok | last post by:
Dear Plese help me. if there is x=5 y=10 now i want z=15 z="x+y" How it is possible?
6
1704
by: bugnthecode | last post by:
I'm writing a program to send data over the serial port. I'm using pyserial, and I'm on WindowsXP. When I use literals I can get the data accross how I want it for example: 1 2 3 4...
7
2239
by: temp34k45k | last post by:
I need to evaluate two strings for their order. The strings contain Letters (A thru Z upper case only) and Numbers (0-9) and the decimal point (.). I need an order like the list that follows: ...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.