Php Array Get Previous And Next Element?
Hi guys,
Today i will explained to the How To Get previous and next element in php array. This example is so easy to use in php. THis example to use current() and next() and prev() function to use.
Current(),next() and prev() function is provides to the php. The current() function is use array current value set and next() function is use next value set and prev() function is use previous value set in php array.
So let's start to the example and follow to the my all step.
Solution
echo current($language) . "<br>";
echo next($language) . "<br>";
echo prev($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 next($language) . "<br>";
echo prev($language);
?>
Output :
laravel
php
laravel
So, finally we are done with our code we can get below output.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example