PHP Tutorial : Looping numbers/array values

Do you want to generate a lot of numbers in a range with a php loop? Or, you may want to generate a dynamic menu from a php array or something and dont know how to get out the values from this array.

Here is for the numbers, it can be done in two ways, using range function (only php 5) or manually estabilish them.

<?php

for($i < 0; $i < 10; $i++) {
print $i;
}
//or using range

$nrs = range(0,10);

foreach($nrs as $nr) {
print $nr;
}
//Here is to extract from array

$values = array("banana", "something", "apple");

foreach($values as $products) {
print $products;
}
?>
This entry was posted in Basic PHP and tagged , , , , , , , . Bookmark the permalink.

5 Responses to PHP Tutorial : Looping numbers/array values

  1. SonyaSunny says:

    Hi,
    Great job. But not enought info. Where can i read more?

    Thanks
    SonyaSunny

  2. admin says:

    On the php official website!

  3. Come on guys theres hardly and comments on this article!

  4. O.K, you got me this is like my 3rd comment here today I cant wait for your next article!

  5. I like that you update your blog quite a bit it keeps me coming back all the time.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>