Q:

Write a PHP program to get the last element of a given list

0

Write a PHP program to get the last element of a given list

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function last($items)
{
    return end($items);
}

print_r(last([1, 2, 3]));
echo "\n";
print_r(last([2, 1, 3, -4, 5, 1, 2]));

?>

Sample Output:

3
2

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now