callback function return return($var & 1)?

前端 未结 8 2127
灰色年华
灰色年华 2020-12-05 22:07

I have read the PHP Manuel about array_filter



        
8条回答
  •  盖世英雄少女心
    2020-12-05 22:46

    An odd number has its zeroth (least significant) bit set to 1:

               v
    0 = 00000000b
    1 = 00000001b
    2 = 00000010b
    3 = 00000011b
               ^
    

    The expression $var & 1 performs a bitwise AND operation between $var and 1 (1 = 00000001b). So the expression will return:

    • 1 when $var has its zeroth bit set to 1 (odd number)
    • 0 when $var has its zeroth bit set to 0 (even number)

提交回复
热议问题