function findElementThatAppearsOnceInArray($arr) {
$map = array();
foreach ($arr as $x) {
$map[$x] = ($map[$x] ?? 0) + 1;
}
foreach ($map as $key => $value) {
if ($value == 1) {
return $key;
}
}
return -1;
}
$arr = array(3, 5, 5, 2, 7, 3, 2, 8, 8, 3, 2, 5, 8);
echo findElementThatAppearsOnceInArray($arr);
/*
run:
7
*/