php 找出二维数组指定字段最小的下标

function findMinIndex($array, $field) {
    $minValue = null;
    $minIndex = null;

    foreach ($array as $index => $item) {
        if (isset($item[$field])) {
            if ($minValue === null || $item[$field] < $minValue) {
                $minValue = $item[$field];
                $minIndex = $index;
            }
        }
    }

    return $minIndex;
}

 

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/114186.html<

(0)
运维的头像运维
上一篇2025-02-17 19:08
下一篇 2025-02-17 19:09

相关推荐

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注