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 to Date in PHP?
- PHP CURL Post Request with Parameters Example
- PHP Dropzone Display Existing Files from Server Example
- 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?