array_values()
FunctionIf you know the exact index or key of an array you can easily get the first element, like this:
<?php
// A sample indexed array
$cities = array("London", "Paris", "New York");
echo $cities[0]; // Outputs: London
// A sample associative array
$fruits = array("a" => "Apple", "b" => "Ball", "c" => "Cat");
echo $fruits["a"]; // Outputs: Apple
?>
However, there are certain situations where you don't know the exact index or key of the first element. In that case you can use the array_values()
function which returns all the values from the array and indexes the array numerically, as shown in the following example:
<?php
$arr = array(3 => "Apple", 5 => "Ball", 11 => "Cat");
echo array_values($arr)[0]; // Outputs: Apple
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel 8 Create Dummy Data using laravel/tinker Package
Today we will learn how to engender dumm...Laravel 5.6 - Google Firebase Notification In Android
Today, We are going to share with you gu...phpMyAdmin Automatic Logout Time
phpMyAdmin is open-source web based appl...How to get Minimum Value Key in Associative Array in PHP
Today we will share with you one simple...How to implement Datatable in React with Example
In this tutorial, we are going to learn...