- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the first element of an array in PHP?
To get the first element of an array in PHP, the code is as follows −
Example
<?php $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110", "t"=>"115", "u"=>"103", "v"=>"105", "w"=>"125" ); echo "Array value ...
"; echo "Value 1 = " . $arr["p"], "
"; ?>
Output
This will produce the following output−
Array value ... Value 1 = 150
Example
Let us now see another example −
<?php $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110", "t"=>"115", "u"=>"103", "v"=>"105", "w"=>"125" ); echo "Value 1 = " .reset($arr); ?>
Output
This will produce the following output −
Value 1 = 150
- Related Articles
- Get the first element of array in JavaScript
- Get the first element in an array and return using MongoDB Aggregate?
- How to get the first n values of an array in JavaScript?
- How to get only the first n% of an array in JavaScript?
- How to delete an element from an array in PHP and re-index the array?
- How to get random value out of an array in PHP?
- How to get First Element of the Tuple in C#?
- How to get first day of week in PHP?
- Projection of arrays to get the first array element from MongoDB documents
- How to get the first element of the List in Java?
- In PHP, how can I add an object element to an array?
- PHP program to find the minimum element in an array
- PHP program to find the maximum element in an array
- How to delete an array element based on key in PHP?
- Constructing an array of addition/subtractions relative to first array element in JavaScript

Advertisements