How to start a foreach loop at a specific index in PHP

前端 未结 6 2010
野的像风
野的像风 2020-12-08 08:59

I am writing a foreach that does not start at the 0th index but instead starts at the first index of my array. Is there any way to offset the loop\'s starting p

6条回答
  •  感情败类
    2020-12-08 09:31

    Keep it simple.

    foreach ($arr as $k => $v) {
       if ($k < 1) continue;
       // your code here.
    }
    

    See the continue control structure in the manual.

提交回复
热议问题