3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = 1234455; $b = 54456; function digits_in_both($x, $y) { $in_both = []; $split_y = str_split($y); foreach(str_split($x) as $n) { $key = array_search($n, $split_y); if($key !== false) { $in_both[] = $n; unset($split_y[$key]); } } return $in_both; } $in_both = digits_in_both(123445, 54456); var_export($in_both); var_dump(count($in_both));
based on CK81g
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0alpha1
array ( 0 => '4', 1 => '4', 2 => '5', )int(3)