programming-examples/php/Basics/PHP program to find the single element appears once in an array where every element appears twice except for one.php

15 lines
281 B
PHP
Raw Normal View History

2019-11-18 14:44:36 +01:00
<?php
function single_number($arr)
{
$result = 0;
for($i=0; $i<sizeof($arr); $i++)
{
$result = $result ^ $arr[$i];
}
return $result;
}
$num = array(5, 3, 0, 3, 0, 5, 7, 7, 9);
print_r(single_number($num)."\n")
?>