get first and last element in array

后端 未结 6 1955
暗喜
暗喜 2020-12-08 06:30

hey there i have this array:

array(1) {
  [\"dump\"]=>
  string(38) \"[\"24.0\",24.1,24.2,24.3,24.4,24.5,24.6]\"
}

my question:

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 07:11

    reset() and end() does exactly this.

    From the manual:

    reset(): Returns the value of the first array element, or FALSE if the array is empty.

    end(): Returns the value of the last element or FALSE for empty array.

    Example:

    
    

    Which outputs:

    float(24)
    float(24.6)

    DEMO


    NOTE: This will reset your array pointer meaning if you use current() to get the current element or you've seeked into the middle of the array, reset() and end() will reset the array pointer (to the beginning and to the end):

提交回复
热议问题