Write a PHP program to find the single element appears once in an array where every element appears twice except for one.
Input : array(5, 3, 0, 3, 0, 5, 7, 7, 9)
<?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") ?>
Sample Output:
9
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer