473,326 Members | 2,104 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,326 software developers and data experts.

foreach statements - can you help?

Hi all

I cant itterate through an array! Why doesn't this code work?

<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];
}
*/

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

?>
</body>
</html>
Thanks in advance for your help.
Jul 17 '05 #1
2 1353
"siu02rk" <si*****@hotmail.com> wrote in message
news:82**************************@posting.google.c om...
Hi all

I cant itterate through an array! Why doesn't this code work?

<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];
}
*/

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

?>
</body>
</html>
Thanks in advance for your help.


In your first (commented out) iteration of $rabbit, you left out the $
symbol in the for() statement. for(p=0;p<3;p++) should be
for($p=0;$p<3;$p++).

In your second iteration (the foreach() one), you gave the foreach()
"parameters" in the wrong order. It should be foreach($rabbit as $k). Also,
take away the semicolon at the end of that line.

- JP
Jul 17 '05 #2
*** siu02rk escribió/wrote (11 Sep 2004 17:10:11 -0700):
foreach($k as $rabbit);
{
echo "$k";
}


Figuring out what arguments functions expect makes coding unnecessarily
difficult. That's why there's a manual that explains it ;-)

http://www.php.net/foreach

--
-+ Á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

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

Similar topics

35
by: jerrygarciuh | last post by:
Hi all, I was just wondering what popular opinion is on PHP giving this warning: Warning: Invalid argument supplied for foreach() in /home/boogerpic/public_html/my.php on line 6 when...
1
by: Adam | last post by:
Hi, I am having a rather frustrating time with a script I am working on. I am looping through the elements of an array with a foreach statment and inside the foreach statement I have two if...
4
by: Tony | last post by:
I'm trying to simplify a list of statements similar to the following: document.getElementById('header').style=default.header; document.getElementById('header').style=default.header;...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
4
by: bg_ie | last post by:
Hi, What is wrong with the following - short arrfile = new short; foreach (short s in arrfile) { s = 10; }
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...
7
by: Tony Johansson | last post by:
Hello! Why does not this cause a compile error because a ulong has never been implicitly convertible to byte? ulong vektor = {100000,200000,300000}; foreach(byte b in vektor) {...
0
by: Sam | last post by:
Have been trying to do this in flexy for a while, but it does not seem to support it. I have an array of categories of which each contains an array of things. So I'd like the template to look like...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.