Arrays: array_shift($arr) or $arr[0]?

前端 未结 11 602
说谎
说谎 2021-01-14 04:08

Which one would you use?

Basically I only want to get the 1st element from a array, that\'s it.

11条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 04:24

    If you want the first element of an array, use $arr[0] form. Advantages - Simplicity, Readability and Maintainability. Keep things straight forward.

    Edit: Use index 0 only if you know that the array has default keys starting from 0.

提交回复
热议问题