PHP Index

In order to become familiar with PHP programming structures and commands, we will build various PHP pages. Sections of this page will explain each PHP command, provide a link to a working sample, and detail the working sample's PHP code. Let's get started:

Math

Math is fairly easy with PHP. You are already familiar with the most common math operators:

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (returns the remainder between two numbers)
  • For example: math.php


    <html>
    <head>
    <title>math.php</title>
    </head>
    <body>
    <?php

    $additionanswer 
    100+10;
    //Online Calculator

    Print("<h1> Online Calculator </h1>");

    //Display math output
    print ("100 + 10 = " . (100 10). " Addition <br>");
    print (
    "100 - 10 = ". (100-10) ." Subtraction <br>");
    print(
    "100 * 10 = ". (100*10) ." Multiplication <br>");
    print(
    "100 / 10 = ". (100/10) ." Division <br>");
    print(
    "99 % 10 = ". (99%10) ." Modulus (the remainder!) <br>");

    ?>

    </body>
    </html>

    In addition to the main math operators, there are also many math functions to use, including abs (absolute value), is_nan (is not a number), max (maximum), and min (minimum).