How to limmit the times a loop is repeated.

Discussion in 'PHP' started by lruneh, Oct 22, 2008.

  1. #1
    Hi all,

    I'm not that great at php, so please bare with me. Any help will make me very happy :rolleyes:

    I need to limit the ammount of times this loop is repeated:

    foreach ($something->items as $item) {}
    Code (markup):
    I would imagine that Iwill have to change foreach into while or do, but how do I keep the $something->items as $item-part and limit the number of times the code is executed?

    Hope this makes sence and thank you for any help you give me.
     
    lruneh, Oct 22, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $i = 1;
    foreach() {
    if($i >= 10) break;
    $i++;
    }
     
    Kyosys, Oct 22, 2008 IP
    lruneh likes this.
  3. lruneh

    lruneh Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OMG! That's so simple. Thank you very much!
     
    lruneh, Oct 22, 2008 IP
  4. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no problem
     
    Kyosys, Oct 22, 2008 IP