How to get maximum key/values pair array from a associative array in PHP?
Get the solution ↓↓↓Solution:
You can use bellow approach for getting your result :
$array = array(
array('K1'=>'v1'),
array('K1'=>'v1','K2'=>'v2'),
array('K1'=>'v1','K2'=>'v2','K3'=>'v3')
);
$maxs = array_keys($array, max($array));
print_r($maxs);
It will provide you output as :
Array ( [0] => 2 )
Then you can get your key value pairs according to your requirement after passing this maxs array value like this.
$myMaxValue = $array[$maxs[0]];
print_r($myMaxValue);
This provide you below result :
Array ( [K1] => v1 [K2] => v2 [K3] => v3 )
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreign key constraint is incorrectly formed laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.