如何让所有的最低值内多维数组?

编程入门 行业动态 更新时间:2024-10-25 02:26:22
本文介绍了如何让所有的最低值内多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的code:

< PHP$结果=阵列(阵列(分裂=>2,二合一=>中4,3),                  阵列(分裂=>2,二合一=>中6,1),                  阵列(分裂=>3,二合一=>中2,1),                  阵列(分裂=>4,二合一=>中1,1,1,1));$ min_x =分钟(array_column($结果,'拆'));的print_r($ min_x);?>

这会给我 2 的结果,我需要创建一些函数来获得组合值的 2 ,如何获得这两个数组值 2 使用本地PHP函数(有没有?)是这样的:

阵列(阵列(分裂=>2,二合一=>中4,3),        阵列(分裂=>2,二合一=>中6,1));

解决方案

您可以用得到的最少数量分和 array_column 最后索性用 array_filter

$结果=阵列(阵列(分裂=>2,二合一=>中4,3),                  阵列(分裂=>2,二合一=>中6,1),                  阵列(分裂=>3,二合一=>中2,1),                  阵列(分裂=>4,二合一=>中1,1,1,1));$分= MIN(array_column($结果,'拆'));$解析度= array_filter($结果,功能($ V)的使用(分$){    返回$ V ['分裂'] == $分钟;});的print_r($水库);

输出:

阵列(    [0] =>排列        (            [分体式] => 2            [组合] => 4,3        )    [1] =>排列        (            [分体式] => 2            [组合] => 6,1        ))

  

注:与PHP版本工作> = 5.5.0

I have this code :

<?php $result = array ( array ("split" => "2", "combo" => "4,3"), array ("split" => "2", "combo" => "6,1"), array ("split" => "3", "combo" => "2,1"), array ("split" => "4", "combo" => "1,1,1,1")); $min_x = min ( array_column( $result, 'split' ) ); print_r($min_x); ?>

this will give me 2 as result and I need to create some function to get the combo value of 2, how to get both array value of 2 using native PHP function (is there any?) like this :

array ( array ("split" => "2", "combo" => "4,3"), array ("split" => "2", "combo" => "6,1"));

解决方案

You can get the minimum number using min and array_column and finally simply use array_filter

$result = array ( array ("split" => "2", "combo" => "4,3"), array ("split" => "2", "combo" => "6,1"), array ("split" => "3", "combo" => "2,1"), array ("split" => "4", "combo" => "1,1,1,1")); $min = min(array_column($result,'split')); $res = array_filter($result,function($v)use($min){ return $v['split'] == $min; }); print_r($res);

Output:

Array ( [0] => Array ( [split] => 2 [combo] => 4,3 ) [1] => Array ( [split] => 2 [combo] => 6,1 ) )

Note : Working with PHP version >= 5.5.0

更多推荐

如何让所有的最低值内多维数组?

本文发布于:2023-11-22 20:04:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多维   数组   低值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!