I have this array
$data['key'] = array(11,5,7);
$data['value'] = array(78,54,96);
I have sorted it based on value. So now I have -
$data['key'] = (5,11,7); $data['value'] = (54,78,96);
How can i get the first set of key-value pair i.e. the one which has the min value.
I want the o/p as -
(5,54)
can someone pls explain how this can be done?
$data['key'] = array(11,5,7);
$data['value'] = array(78,54,96);
$min = min($data['value']);
$key = array_search($min,$data['value']);
$result = array($data['key'][$key],$min);
You can use asort and get only the first key and value.
asort($data);
foreach($data as $key=>$val) {
echo $key." ".$val; break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With