php - what does this mean return($var & 1); -


this question has answer here:

in php in line below return($var & 1); mean, & mean in context?

<?php function test_odd($var) { return($var & 1); }  $a1=array("a","b",2,3,4); print_r(array_filter($a1,"test_odd")); ?> 

this bitwise and.

so, if $var odd returns 1.

let's $var = 13 , in binary 1101 (because 13 = 2^3 + 2^2 + 2^0).

when 1101 & 0001 0001. can either 1 if $var has last bit 1 (meaning it's odd) or 0 if $var has 0 last bite, meaning $var written sum of powers of two, without 2^0` meaning even.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -