ItSolutionStuff.com

How to Get First Element of Array in PHP?

By Hardik Savani • May 14, 2024
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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Last Word from String in PHP?

Read Now →

How to Remove Last 2, 3, 4, 5, 7 Characters of a String in PHP?

Read Now →

How to Get Last 2, 3, 4, 5, 7 Characters of a String in PHP?

Read Now →

How to Upgrade PHP Version from 8.1 to 8.2 in Ubuntu?

Read Now →

How to Subtract Days to Date in PHP?

Read Now →

PHP Curl POST Request with Headers Example

Read Now →

How to Generate 4,6,8,10 Digit Random number in PHP?

Read Now →

PHP Move File from One Folder to Another Example

Read Now →

PHP Copy File from One Folder to Another Example

Read Now →

PHP Webcam Capture Image and Save from Camera

Read Now →

How to Upload and Resize Image in PHP?

Read Now →

PHP Import Excel File into MySQL Database Tutorial

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Get File Name without Extension in PHP?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →