473,320 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using FOR loop - Can you help?

Hi All,

Why doesn't the For Loop output the array "rabbit"? Here is the code :

<html>
<title> Hello World Script </title>
<body>
<?php
$Name="Joe Blogg";
$a=a;
$b=b;
$rabbit[0]="Test";
$rabbit[1]="The";
$rabbit[2]="Array";

echo "Hello World";

echo "<p> My name is "."$Name </p>";

echo $a." ".$b;

echo "$rabbit[0] $rabbit[1] $rabbit[2]";

echo "<p>";

for ($i=1;$i<13;$i++)
{
echo "\n Multiply by $i : ";
echo "<p>";
for($e=1;$e<13;$e++)
{
$result = $i * $e;
echo "$i x $e = $i * $e";
echo "<p>";
}
}

for ($p=0;$p<3;$p++)
{
echo $rabbit[p];
}
?>
</body>
</html>
Jul 17 '05 #1
8 1911
On 9 Sep 2004 14:29:16 -0700, si*****@hotmail.com (siu02rk) wrote:
Why doesn't the For Loop output the array "rabbit"? Here is the code :


[code snipped]

Set error_reporting to E_ALL and make sure display_errors is on. You will
receive a ton of warnings, many of which will explain why your code doesn't
work as you expected.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
*** siu02rk escribió/wrote (9 Sep 2004 14:29:16 -0700):
echo $rabbit[p];

^^^

This is an (probably undefined) constant, not a variable.

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #3
JV

"siu02rk" <si*****@hotmail.com> wrote in message
news:82**************************@posting.google.c om...
Why doesn't the For Loop output the array "rabbit"? Here is the code :
$rabbit[0]="Test";
$rabbit[1]="The";
$rabbit[2]="Array";
NOTE: here you are creating an array : P
echo "$rabbit[0] $rabbit[1] $rabbit[2]";
ok echoing individual array items
for ($p=0;$p<3;$p++) {
echo $rabbit[p];
}


k when you want to output the total array, I find that this works much
better

foreach ($ind as $rabbit){
echo "$ind ";
}

this loop takes each item in the array and sets $ind = item then runs loop
until end of array or empty value (not sure which)
BTW im kinda new to this whole PHP thing too so no biggie

HTH
JV
Jul 17 '05 #4

On 10-Sep-2004, "JV" <jveil.hotpop@com> wrote:
foreach ($ind as $rabbit){
echo "$ind ";
}

this loop takes each item in the array and sets $ind = item then runs loop
until end of array or empty value (not sure which)


It is just the other way around here, so

foreach ($rabbit as $ind) {echo "$ind";}

see: http://nl3.php.net/foreach
Bert
Jul 17 '05 #5
siu02rk wrote:
Hi All,

Why doesn't the For Loop output the array "rabbit"? Here is the code
echo "$rabbit[0] $rabbit[1] $rabbit[2]";

echo "<p>";

for ($i=1;$i<13;$i++)
{
echo "\n Multiply by $i : ";
echo "<p>";
for($e=1;$e<13;$e++)
{
$result = $i * $e;
echo "$i x $e = $i * $e";
echo "<p>";
}
}

for ($p=0;$p<3;$p++)
{
echo $rabbit[p];
}

</body>
</html>


You forgot the $ before p. Now it is a non-defined constant.
Jul 17 '05 #6
Pjotr Wedersteers wrote:
You forgot the $ before p. Now it is a non-defined constant.


Is there a setting to flag that as an error?

Brian
Jul 17 '05 #7
Default User wrote:
Pjotr Wedersteers wrote:
You forgot the $ before p. Now it is a non-defined constant.


Is there a setting to flag that as an error?

Brian


You could (assuming you have control over the Web/PHP server) set the level
of warnings to include E_NOTICE in php.ini
Also check out PHP's error_reporting function:
http://php.net/error_reporting on how to define your own settings per
individual script.
The use of unassigned constants sollicitates an E_NOTICE.

I use PHPEdit as Development Tool (when used only for non commercial
personal stuff it is FREE) which reports all error levels by default, in a
clear dialog window and the windows error sound. (I like the editor
particularly, the debugger needs some debugging still, a newer release is
expected shortly. Get a copy at www.waterproof.fr)

HTH
Pjotr
Jul 17 '05 #8
Pjotr Wedersteers wrote:
Default User wrote:
Pjotr Wedersteers wrote:
You forgot the $ before p. Now it is a non-defined constant.
Is there a setting to flag that as an error?

You could (assuming you have control over the Web/PHP server) set the
level of warnings to include E_NOTICE in php.ini
Also check out PHP's error_reporting function:
http://php.net/error_reporting on how to define your own settings per
individual script.

Ok, good. That's one of those little things that tends to get those of
us more used to programming in C and such, and end up forgetting the $
every now and then.

Brian
Jul 17 '05 #9

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

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
13
by: Bev in TX | last post by:
We are using Visual Studio .NET 2003. When using that compiler, the following example code goes into an endless loop in the "while" loop when the /Og optimization option is used: #include...
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
1
by: Thiero | last post by:
Hi I posted s thread but did have any reply, I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.