如何让所有的最低值内多维数组? [英] How To Get ALL Minimum Value Within Multidimensional Array?
本文介绍了如何让所有的最低值内多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的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 thecombo value
of2
, how to get both array value of2
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
andarray_column
and finally simply usearray_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
这篇关于如何让所有的最低值内多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文