The Math Functions


Besides the math operators, PHP comes with all kinds of math functions built inhere's the list of what's available to you in your scripts:

  • abs. Absolute value

  • acos. Arc cosine

  • acosh. Inverse hyperbolic cosine

  • asin. Arc sine

  • asinh. Inverse hyperbolic sine

  • atan2. Arc tangent of two variables

  • atan. Arc tangent

  • atanh. Inverse hyperbolic tangent

  • base_convert. Converts a number between bases

  • bindec. Converts binary to decimal

  • ceil. Rounds fractions up

  • cos. Cosine

  • cosh. Hyperbolic cosine

  • decbin. Converts decimal to binary

  • dechex. Converts decimal to hexadecimal

  • decoct. Converts decimal to octal

  • deg2rad. Converts the number in degrees to the radian equivalent

  • exp. Calculates the exponent of e

  • expm1. Returns exp(number) - 1

  • floor. Rounds fractions down

  • fmod. Returns the floating point remainder of the division of the arguments

  • getrandmax. Shows the largest possible random value

  • hexdec. Converts hexadecimal to decimal

  • hypot. Returns sqrt(num1*num1 + num2*num2)

  • is_finite. Determines whether a value is a legal finite number

  • is_infinite. Determines whether a value is infinite

  • is_nan. Determines whether a value is not a number

  • lcg_value. Combined linear congruential generator

  • log10. Base 10 logarithm

  • log1p. Returns log(1 + number)

  • log. Returns the natural logarithm

  • max. Finds the highest value

  • min. Finds the lowest value

  • mt_geTRandmax. Shows the largest possible random value

  • mt_rand. Generates a better random value

  • mt_srand. Seeds the better random number generator

  • octdec. Converts octal to decimal

  • pi. Gets the value of pi

  • pow. Exponential expression

  • rad2deg. Converts the radian number to the equivalent number in degrees

  • rand. Generates a random integer

  • round. Rounds a float

  • sin. Sine

  • sinh. Hyperbolic sine

  • sqrt. Square root

  • srand. Seed the random number generator

  • tan. Tangent

  • tanh. Hyperbolic tangent

Here's an example, using sqrt to get a square root:

 <?php      echo "sqrt(49) = ", sqrt(49);  ?> 

Here's what you get when you run this script:

 sqrt(49) = 7 

If you ever need some advanced math, PHP has the situation covered.



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net