nested php for loop

Discussion in 'PHP' started by ironmankho, Dec 8, 2012.

  1. #1
    hi i want something with Php for loop like this

    for ($i=1; $i<=100; $i++)
    {
    echo $i."<br />";
    }
    /// out put

    1.green
    2.yellow
    3.orange
    4.blue
    5.green
    6.yellow
    7.orange
    8.blue
    9.green
    10.yellow
    11.orange
    12.blue
    13.green
    14.yellow
    15.orange
    16.blue
     
    Last edited: Dec 8, 2012
    ironmankho, Dec 8, 2012 IP
  2. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    <?php
    $colors = new InfiniteIterator(new ArrayIterator(array("Red","blue","green","orange")));
    for ($colors->rewind(), $i=1;
    $color = $colors->current(), $i<=500;
    $i++, $colors->next()
    ) {
    echo "The number is $i the color $color\n";
    }
    ?>
     
    ironmankho, Dec 8, 2012 IP