

PHP Find Key of Minimum value in Given Array
source link: https://www.laravelcode.com/post/php-find-key-of-minimum-value-in-given-array
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.

PHP Find Key of Minimum value in Given Array
On working with huge data, sometimes you might needed to get the key of minimum value of given array. You can do it with your custom function. Below is the example I found very simple and easy.
<?php
$arr = [
0 => 3425,
1 => 1567,
2 => 785,
3 => 4181
];
$min_val_id = min(array_keys($arr, min($arr)));
echo($min_val_id); // 2
So what the above code does is first check the minimum value from array using min()
function and array_keys() function returns array of key. Then outer min() function returns single value of that key which is key of minimum value from give array.
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
-
13
Leetcode Find Minimum in Rotated Sorted Array 题解 当前位置:XINDOO > 算法 > 正文
-
10
题目¶ 原题地址: https://leetcode.com...
-
7
题目¶ 原题地址: https://leetcode.com/probl...
-
11
Count minimum steps to get the given desired arraySkip to content
-
3
In this article, we will discuss different ways to find the minimum value in an array and also its index position. Table Of Contents Problem Description Here we are given an array a...
-
11
Find GCD of Array after subtracting given value for M queriesDifficulty Level : HardLast Updated : 12 Dec, 2022
-
5
PHP search array key by value in array 868 views 1 year ago PHP Hello guys While working with PHP array, you may...
-
12
How to get Minimum Value Key in Associative Array in PHP 1301 views 1 year ago PHP Today we will share with you one sim...
-
7
Minimum steps required to reach the end of Array with a given capacityGiven an array arr[] of size n. You will have to traverse the array from left to right deducting each element of...
-
5
Construct minimum length array with given conditionskamabokogonpachiroGiven an array, A[] of N integers and 2 integers P ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK