Search code examples
phparrayselement

How to access the last element in an array?


$array = explode(".", $row[copy]);
$a = $array.length -1;

I want to return the last element of this array but all i get from this is -1.


Solution

  • You can also use:

    $a = end($array);
    

    This also sets the arrays internal pointer to the end of the array, but it does get you the last element easily.