At least go through them all, traverse or something else
Then perform XOR in sequence, and the final result is that number
Example:
<code><span>// 示例数组</span><span>$arr</span> = <span>array</span>(<span>1</span>, <span>2</span>, <span>2</span>, <span>3</span>, <span>1</span>, <span>3</span>, <span>4</span>, <span>5</span>, <span>5</span>); <span>// 0与任何数异或都是其本身</span><span>$res</span> = <span>0</span>; <span>foreach</span> (<span>$arr</span><span>as</span><span>$value</span>) { <span>// 相同两个数异或结果为0</span><span>$res</span> = <span>$res</span> ^ <span>$value</span>; } var_dump(<span>$res</span>);</code>
The above introduces that there are N numbers, and only one number appears an odd number of times. How to find this number? , including relevant content, I hope it will be helpful to friends who are interested in PHP tutorials.