Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Get First Element of Array

php

This example will teach you how to retrieve the first element of an array in PHP. I simply walked you through the process of getting the first element of an array in PHP. I simply provided an example of how to use php to fetch the first key of an array. I would like to demonstrate how to retrieve the first key value from an array in PHP.

To retrieve the first element of an array in PHP, we will utilize the array_shift() and array_values() functions. So let us look at the short code for it.

Eaxmple

<?php
  
   $myArray = ["One", "Two", "Three", "Four"];
      
   $firstElem = array_shift(array_values($myArray));   
     
   var_dump($firstElem);
     
?>

OutPut:

string(3) "One"
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x