0

I have a function in JavaScript:

function myFunc(a, b, c)
{
  return (a ^ (b | (~c)));
}

And Equivalent in PHP:

function myFunc($a, $b, $c)
{
    return ($a ^ ($b | (~$c)));
}

The result for them are not the same:

myFunc('123', '4434', '355'); // PHP = ��� (Unknown Characters)
myFunc('123', '4434', '355'); // JavaScript = -91

What is wrong here?

1
  • 1
    From the manual: if the operands are strings, then the operation will be performed on the ASCII values of the characters that make up the strings Commented May 24, 2015 at 12:43

1 Answer 1

2

In PHP you need to cast manually to integer

function myFunc($a, $b, $c)
{
    return ((int)$a ^ ((int)$b | (~(int)$c)));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.