%
is the same in PHP and JS, the Modulus operator, aka the remainder.
eg:
10 % 9 = 1
10 % 8 = 2
10 % 7 = 3
10 % 6 = 4
10 % 5 = 0
10 % 4 = 2
10 % 3 = 1
10 % 2 = 0
10 % 1 = 0
質問
I am converting these functions http://www.movable-type.co.uk/scripts/latlong.html to PhP so they can be run server side.
I have the following line of code in Javascript (line 201)
alpha1 = (brng13 - brng12 + Math.PI) % (2*Math.PI) - Math.PI;
and so far in php I have got
$alpha1 = ($brng13 - $brng12 + pi()) % (2*pi()) - pi();
However I do not know what that %
stands for in Javascript and what its equivalent conversion into PHP would be.
Any insight would be appreciated.
Thanks
解決
%
is the same in PHP and JS, the Modulus operator, aka the remainder.
eg:
10 % 9 = 1
10 % 8 = 2
10 % 7 = 3
10 % 6 = 4
10 % 5 = 0
10 % 4 = 2
10 % 3 = 1
10 % 2 = 0
10 % 1 = 0
他のヒント
That's the modulus operator. PHP uses the same thing. (Come to think of it, I don't know of a language that doesn't.)
Of course, running these two code samples and seeing the runtime values would indicate pretty clearly if the operators are doing the same thing...
Javascript operators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
PHP operators: http://php.net/manual/en/language.operators.arithmetic.php
The % operator is called the modulus operator, or the "remainder" operator. It is common to many programming languages and as far as I know performs the same operation in both Javascript and PHP. Either of the links above should lead you to a good definition of what it does.