<?php $array1 = [1, 3, 3, 3, 4, 7, 7, 8, 8]; $array2 = [0, 3, 3, 4, 4, 9, 9, 9]; $counts1 = array_count_values($array1); $counts2 = array_count_values($array2); $allCounts = $counts1 + $counts2; $result = []; array_walk( $allCounts, function($v, $k) use(&$counts1, &$counts2, &$result) { array_push( $result, ...array_fill( 0, max($counts1[$k] ?? 0, $counts2[$k] ?? 0), $k ) ); } ); var_export($result);
You have javascript disabled. You will not be able to edit any code.