That won't work if the value of the last element is not unique in the array.
$last_val = end($array);
$last_key = key($array);
reset($array); // Not necessary if using "foreach" loop)
foreach ($array as $key => $val) {
if (key($array) == $last_key) {
// Do something
}
}
Depending on what you want to do with the last element, there's probably a better approach.
Edit: Incorrect statement revised.