javascriptphpcode-migration

PHP equivalent of Javascript %


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


Solution

  • % 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