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;
}
?>

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. unmetered master reseller hosting Says:

    Come on guys theres hardly and comments on this article!


  4. unmetered shared hosting Says:

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


  5. shared hosting Says:

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


Leave a Reply

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