How To Get First And Last Value In Php?

PHP 8 , PHP

Nicesnippets

394

04-06-2021


How To Get First And Last Value In Php?

Hi guys,

Today i will explained to the How To Get First And Last Value In Php. This example is so easy to use in php. THis example to use current() and end() function to use.

Current() and end() function is provides to the php. The current() function is use array first value and end() function is use last value of array.

So let's start to the example and follow to the my all step.

Solution


echo current($language) . "<br>";

echo end($language);

Example :

This exampel to i will used to 4 value array create.

<?php

$language = array("laravel", "php", "java", "odo");

echo current($language) . "<br>";

echo end($language);

?>

Output :

laravel

odo

So, finally we are done with our code we can get below output.


Recommended Posts