How to get Minimum Value Key in Associative Array in PHP
source link: https://www.laravelcode.com/post/how-to-get-minimum-value-key-in-associative-array-in-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to get Minimum Value Key in Associative Array in PHP
Today we will share with you one simple but very helpful tutorials of PHP. how to find the minimum values' key in an associative array in PHP.
for example, you have the following array and you want to find the minimum value's key from the array.
$pets = array(
"cats" => 1,
"dogs" => 2,
"fish" => 3
);
you can get the minimum value's key from this array some following ways.
Example : 1
$pets = array(
"cats" => 1,
"dogs" => 2,
"fish" => 3
);
array_keys($pets, min($pets)); # array('cats')
Example : 2
$pets = array(
"cats" => 1,
"dogs" => 2,
"fish" => 3
);
array_search(min($pets), $pets);
We hope it can be helped a lot.
Author : Harsukh Makwana
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]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK