How to Get First Element of Array in PHP?
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.
$myArray = ["One", "Two", "Three", "Four"];
$firstElem = array_shift(array_values($myArray));
I hope it can help you...
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?