PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function findMajorityElement(array $inputArray = null): string|int|null { $countValues = array_count_values($inputArray); var_dump($countValues); arsort($countValues, SORT_REGULAR); $expectedMajorityElement = reset($countValues); if (count($inputArray) / 2 > $expectedMajorityElement) { return "Current array doesn't have a majority element."; } return key($countValues); } /* Не могу понять, как сделать проверку, если введённый массив [null,null,null и т.д] и вернуть null. php unit: "Expected result should be null" => [null, [null, null, null]], */ print_r([null, null]);
Show:  
Copy Clear