Bifalgorithm post · Computer science one · Comments

How can PHP libraries and math functions be used?

How can PHP libraries and math functions be used? (Computer science one · Comments) — "PHP has many built-in functions that you can use. These standard librari…

Ideas in this flowchart

  • PHP provides many built-in functions through standard libraries.
  • Standard libraries are available without importing or including them.
  • The PHP manual provides online documentation for these functions.
  • Manual pages include developer comments, explanations, tips, suggestions, and sample code.
  • The math library is a useful collection of PHP functions.
  • The math library is adapted from C, so its function names are the same.
  • Basic functions include absolute value, ceiling, floor, powers, and square roots.
  • Trigonometric functions include cosine, sine, and tangent.
  • Exponential and logarithmic functions include exp, log, and log10.
  • Trigonometric functions use radians rather than degrees.
  • Logarithm functions require positive input values.
  • A function is used by passing input and assigning its returned output to a variable.
  • For example, sqrt($x) and sin($x) receive $x and return results assigned to other variables.
  • PHP also supports exponentiation with the ** operator.
Feed/

How can PHP libraries and math functions be used?

No cover

Channel

Computer science one

1 page

"PHP has many built-in functions that you can use. These standard libraries are loaded and available to use without any special command to import or include them. Full documentation on each of these functions is maintained in the PHP manual, available online at http://php.net/. The manual’s web pages also contain many curated comments from PHP developers which contain further explanations, tips & tricks, suggestions, and sample code to provide further assistance. There are many useful functions that we’ll mention as we progress through each topic. One especially useful collection of functions is the math library. This library is directly adapted from C’s standard math library so all the function names are the same. It provides many common mathematical functions such as the square root and natural logarithm. Table 37.1 highlights several of these functions; full documentation can be found in the PHP manual (http://php.net/manual/en/ref.math.php). To use these, you simply “call” them by providing input and assigning the output to a variable.\n\n$x = 1.5;\n\n$y = sqrt($x); // y now has the value √x = √1.5\n\n$z = sin($x); // z now has the value sin(x) = sin(1.5)\n\nIn both of the function calls above, the value of the variable $x is “passed” to the math function which computes and “returns” the result which then gets assigned to another variable.\n\nTable 37.1: Several functions defined in the PHP math library.\n\nabs($x): Absolute value, |x|\n\nceil($x): Ceiling function\n\nfloor($x): Floor function\n\ncos($x): Cosine function\n\nsin($x): Sine function\n\ntan($x): Tangent function\n\nexp($x): Exponential function, e^x, e = 2.71828...\n\nlog($x): Natural logarithm, ln(x)\n\nlog10($x): Logarithm base 10\n\npow($x,$y): The power function, computes x^y\n\nsqrt($x): Square root function\n\nAll trigonometric functions assume input is in radians, not degrees. Input for the logarithm functions is assumed to be positive, x > 0. Alternatively, PHP supports exponentiation by using x ** y."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.