What does a single ampersand ('&') operator do in PHP?
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
Jaskaran singh Rajal
As a web developer, I pride myself on learning new technologies, continually improving my skill-set and adapting to industry changes. I believe in professionalism, and representing my project based to the highest degree possible. Conceptualist, with a sharp eye for fresh approaches while understanding critical projects include code optimized solutions to achieve desired objectives. The bulk of my experience has involved developing e-commerce stores using the technologies I've listed. In addition to a core strength in PHP development and payment gateways, I have implemented social media aspects to several sites with connectivity APIs including those from Facebook and Twitter.
Updated on June 04, 2022Comments
-
Jaskaran singh Rajal almost 2 years
$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 -
Albzi about 10 yearsAdd an explanation? He asked what it does, not just what it is.
-
Armel Larcier about 10 yearsOr just close this one
-
Albzi about 10 yearsClosed anyway @ArmelLarcier
-
Raptor about 10 yearsMarked as close & added explanation :)
-
Bhargav Kaklotara over 4 years& is bitwise operators which convert operands to bit-level and then perform operation. let me give an example. here are two operands 5 ( 0101 in bit level ) and 1 ( 0001 in bit level ). AND(&) operation of both the numbers will give o/p of 0001, and that will be same for all the odd numbers. so result will be turned on for all odd numbers.
-
Jaskaran singh Rajal almost 3 years@BhargavKaklotara Great