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:
$myArray = ['2'=>'Hey','4'=>'Hello','1'=>'Hi','3'=>'GH'];
$new_key = min(array_keys($myArray));
$new_val = $myArray[$new_key];
I hope it can help you...
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?