leader of this array

A non-empty zero-indexed array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A.

  $A[0] = 1;
  $A[1] = 1;
  $A[2] = 1;
  $A[3] = 50;
  $A[4] = 1;

function solution($A){
  if(empty($A)) return -1;
  
  $array_total_element = count($A);
  $ar_cnt_values = array_count_values($A);

  foreach($ar_cnt_values as $value){
      if($value > $array_total_element/2) return 1;
    }
  return -1;
}

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /home/r8424051/public_html/nibatech.com/wiki/wp-includes/cache.php on line 652