I would like to know, how to start looping of a php array with the second item.
1条回答 默认 最新
- duan0403788996 2014-12-13 13:14关注
Instead of the standard for loop to go through an array, for example:
for($i = 0; $i < count($array); $i++) { echo $array[$i] . " "; }
Outputs "one two three four five".
Just set
$i
equal to 1 instead, like so:for($i = 1; $i < count($array); $i++) { echo $array[$i] . " "; }
Now it outputs this: "two three four five".
However, if you wanted to get the last four items of an array, you can use
array_slice()
.$sliced = array_slice($array, -4); for($i = 0; $i < count($sliced); $i++) { echo $sliced[$i] . " "; }
Outputs "two three four five".
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报