The foreach Statement

The foreach Statement

The foreach statement is used to loop through arrays.

For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) – so on the next loop, you’ll be looking at the next element.

foreach (array as value)
{
code to be executed;
}

Example

The following example demonstrates a loop that will print the values of the given array:

<html>
<body>
<?php
$arr=array(“one”, “two”, “three”);
foreach ($arr as $value)
{
echo “Value: ” . $value . “<br />”;
}
?>
</body>
</html>

and output is

Value: one
Value: two
Value: three

Leave a comment

11 Comments.

  1. Do you know of anywhere else that I can get some information about %keyword%? I have come across your post %title% and it has given me some great ideas, but I am looking for some more information about %keyword% any ideas?

  2. xtmq3v7mtjgyhryv

  3. just learn it and thanks the post again

  4. been following your blog for some days now and i should say i am starting to like your post. and now how do i subscribe to your blog?

  5. been following your blog for some days now and i should say i am starting to like your post. and now how do i subscribe to your blog?

  6. goodto see you make postings on this issue, I should bookmark this web site. Just keep up the good job.

  7. Great write-up, I’m a enormous believer in commenting on blogs and forums to assist the web log authors know that they’ve extra a specific thing of value towards the internet!

  8. when i learning and i just google blog,blog is a good place to learning,i am glad to found your blog

  9. Very good site, where did you come up with the knowledge in this post? I’m happy I found it though, ill be checking back soon to see what other articles you have.

Leave a Reply


[ Ctrl + Enter ]

Trackbacks and Pingbacks:

  • State lottery results - Trackback on 2010/05/19/ 07:08
  • atarax 25 mg online - Trackback on 2010/07/21/ 18:04