How to Get Minimum Key Value of Array in PHP?
Sometimes, you need to get minimum key value of your array but you try to get with loop and any function etc, but in bellow example you can see we can get smallest key value from our php array by using min() and array_keys(). So, let's try to use in your code this way:
index.php
<!DOCTYPE html>
<html>
<body>
<?php
$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];
$new_key = min(array_keys($myArray));
$new_val = $myArray[$new_key];
print_r($new_val);
?>
</body>
</html>
Output:
Hi
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check Current PHP Version in Ubuntu?
- How to Convert String Date to Date Format in PHP?
- PHP curl post request with parameters and get json response
- How to display existing files on server in Dropzone js using PHP
- PHP - import excel file into mysql database tutorial
- How to Get File Name without Extension in PHP?
- PHP Check Word Exist in String or Not Example
- How to Get a Current Page URL in PHP?
- How to Get the File Size in PHP?
- How to Convert Array Values to Lowercase in PHP?
- MySQL Query to Get Current Month Data Example
- How to Find Day Name from Specific Date in PHP?
- How to Remove Null Values from Array in PHP?