How to get minimum key value of array in PHP?

By Hardik Savani | February 12, 2016 | | 30227 Viewer | Category : 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:

Example:

$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];

$new_key = min(array_keys($myArray));

$new_val = $myArray[$new_key];

print_r($new_val);



Hardik Savani
My name is 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, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.