How to Get First Element of Array in PHP?
Hey Developer,
In this example, you will learn php array get first element value. I explained simply step by step how to get first element of array in php. I explained simply step by step php get first key of array example. I would like to show you how to get first key value of array in php.
we will use array_shift() and array_values() function to get first element of array in php. so, let's see the simple code of it.
Example:
index.php
<?php
$myArray = ["One", "Two", "Three", "Four"];
$firstElem = array_shift(array_values($myArray));
var_dump($firstElem);
?>
Output:
string(3) "One"
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Last Word from String in PHP?
- How to Remove Last 2, 3, 4, 5, 7 Characters of a String in PHP?
- How to Get Last 2, 3, 4, 5, 7 Characters of a String in PHP?
- How to Upgrade PHP Version from 8.1 to 8.2 in Ubuntu?
- How to Subtract Days to Date in PHP?
- PHP Curl POST Request with Headers Example
- How to Generate 4,6,8,10 Digit Random number in PHP?
- PHP Move File from One Folder to Another Example
- PHP Copy File from One Folder to Another Example
- PHP Webcam Capture Image and Save from Camera
- How to Upload and Resize Image in PHP?
- PHP Import Excel File into MySQL Database Tutorial
- How to Remove Duplicate Values from Array in PHP?
- How to Get File Name without Extension in PHP?
- How to Get Minimum Key Value of Array in PHP?