Calculate the highest duplicate integers of two associative arrays

后端 未结 4 1773
清歌不尽
清歌不尽 2021-01-25 11:19

Given 2 associative arrays:

$fruits  = array ( \"d\" => \"lemon\", \"a\" => \"orange\", \"b\" => \"banana\", \"c\" => \"apple\" );
$fruits2 = array          


        
4条回答
  •  情深已故
    2021-01-25 11:54

    You're probably chasing the wrong solution. To find the highest duplicate in an array I'd use this (PHP 5.3+ syntax):

    max(array_keys(array_filter(array_count_values($array), function ($i) { return $i >= 2; })))
    

    Do this for both arrays and compare which result is higher. Trying to compare both against each other at the same time is too convoluted.

提交回复
热议问题