How do I check the minimum value inside php array with multiple condition. My array is below:
$arr = [[472 =>['EL' => 52.9,'MT' => 57.375 'MO' => 56.6,'SC' => 26,'ET' => 50.775]],
[505 =>['EL' => 53.425,'MT' => 25,'MO' => 62.8,'SC' => 23,'ET' => 25]]];
$total = array_reduce(
$arr,
function($arr, $key) {
$id = key($key);
$consumed = $key[$id];
$sc = array_keys($consumed);
$arr[$id] = [
"totalc" => array_sum($consumed),
"condition" => array_search('SC', $sc) ? min($consumed) >= 23:min($consumed) >=26
];
return $arr;
},
[]
);
If the key is 'SC', the minimum value for 'SC' is 23, But for the value of other key the minimum value is 26. So the above code must produce the following output:
Array
(
[472] => Array
(
[totalc] => 243.65
[condition] => 1
)
[505] => Array
(
[totalc] => 189.225
[condition] =>
)
)
The SC key in both the array ( [472] and [505] ) meet the minimum condition 23 but the value of the key ET does not meet the minimum condition 26. So the array [505] should produce false on the value of condition key. But if we change the value of ET to 26 or more on the [505] array, we still get false value. But the correct value must be 1 or true. So if the array is like below:
$arr = [[472 =>['EL' => 52.9,'MT' => 57.375 'MO' => 56.6,'SC' => 26,'ET' => 50.775]],
[505 =>['EL' => 53.425,'MT' => 25,'MO' => 62.8,'SC' => 23,'ET' => 26]]];
The correct output would be :
Array
(
[472] => Array
(
[totalc] => 243.65
[condition] => 1
)
[505] => Array
(
[totalc] => 189.225
[condition] => 1
)
)
In short, the min value of 'SC' should be 23 and the mim value of other KEYS(EL, MT,MO,ET) should be 26. I tried to solve this problem for almost two days and two nights, it still does not work. So if you could help me, I would really appreciate it. Thanks