php - How To Get ALL Minimum Value Within Multidimensional Array? -
i have 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 give me 2 result , need create function combo value of 2, how both array value of 2 using native php function (is there any?) :
array ( array ("split" => "2", "combo" => "4,3"), array ("split" => "2", "combo" => "6,1"));
you can minimum number using min , array_column , 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 php version >= 5.5.0
Comments
Post a Comment