本文介绍了如何让所有的最低值内多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的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
更多推荐
如何让所有的最低值内多维数组?
发布评论