Get the first N elements of an array?

后端 未结 5 1542
一整个雨季
一整个雨季 2020-11-27 02:19

What is the best way to accomplish this?

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 03:18

    if you want to get the first N elements and also remove it from the array, you can use array_splice() (note the 'p' in "splice"):

    http://docs.php.net/manual/da/function.array-splice.php

    use it like so: $array_without_n_elements = array_splice($old_array, 0, N)

提交回复
热议问题