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;
}

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容