8
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
print_r(array_filter($array1, "odd"));


function odd($var)
{
    // returns whether the input integer is odd//

    return($var & 1);
}

In the return value what do & operator ?? how it return odd number

user2864740
  • 57,407
  • 13
  • 129
  • 202
Jaskaran singh Rajal
  • 2,201
  • 2
  • 15
  • 27
  • 4
    RTFM: http://www.php.net/manual/en/language.operators.bitwise.php – CBroe Mar 13 '14 at 10:51
  • The usage of `&` here has nothing to do with arrays .. consider if there was no array and odd was called as `odd(13)` and `odd(42)`. – user2864740 Mar 13 '14 at 10:52
  • goto https://www.php.net/manual/en/function.array-filter.php -> User Contributed Notes -> searchBy("nicolaj")->read() – habibun Jun 02 '21 at 10:43

1 Answers1

9

It is bitwise operator AND.

For example, ($a & $b) evaluates both $a and $b is turned "on" (i.e. equal to 1)

See this: http://www.php.net/manual/en/language.operators.bitwise.php

Raptor
  • 51,208
  • 43
  • 217
  • 353