get first and last element in array

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:

<?php
    $array = array(24.0,24.1,24.2,24.3,24.4,24.5,24.6);
    
    $first = reset($array);
    $last = end($array);
    
    var_dump($first, $last);
?>

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):

<?php

$array = array(30.0, 24.0, 24.1, 24.2, 24.3, 24.4, 24.5, 24.6, 12.0);
    
// reset — Set the internal pointer of an array to its first element
$first = reset($array);

var_dump($first); // float(30)
var_dump(current($array)); // float(30)

// end — Set the internal pointer of an array to its last element
$last = end($array);
    
var_dump($last); // float(12)
var_dump(current($array)); // float(12) - this is no longer 30 - now it's 12

You can accessing array elements always with square bracket syntax. So to get the first use 0, as arrays are zero-based indexed and count($arr) - 1 to get the last item.

$firstEle = $arr[0];
$lastEle = $arr[count($arr) - 1];

As of PHP 7.3, array_key_first and array_key_last is available

$first = $array[array_key_first($array)];    
$last = $array[array_key_last($array)];