Header Ads

Header ADS

Get First and Last Element of Array in php

 <?php

/* Sample array */

$myArray = array("apple", "banana", "orange", "grape", "kiwi");

/* Get the first element */

$firstElement = reset($myArray);

/* Get the last element */

$lastElement = end($myArray);

/* Output the results */

echo "First element: " . $firstElement . "\n";

echo "Last element: " . $lastElement . "\n";

?>


output:


First element: apple

Last element: kiwi

No comments

Theme images by fpm. Powered by Blogger.