I am converting a C# routine to php
do not understand how to do this C#
bool ret = false;
ret ^= (y * multiple[i] + constant[i] < x);
its the operator ^=
??
Short answer: in PHP you can use the same ^=
operator.
The x ^= y
is equivalent to x = x ^ y
with ^
the bitwise xor operator.
In PHP ^
is also the bitwise xor operator. So it is the same in PHP, you can use:
$ret ^= ($y * $multiple[$i] + $constant[$i] < $x);
given of course that $y
, $multiple
, $i$
, etc. all have an equivalent meaning.
In C# there is a feature of assigning and using an operator at the same time. Usually denoted by ending with =
. For example:
int b = 5;
Console.WriteLine(b += 2); //Add 2 to b and print it
b *= 2; //Equivalent of b = b * 2;
Console.WriteLine(b);
The above code prints: 7 14
Hope this helps you better understand how assignment and arithmetic operators work. Here is a link to some reference on the particular operator in your question.