Page 510 - Computer_Science_F5
P. 510

Basics of PHP: syntax, commenting, variables, and the Echo statement
              In this section,  we cover the basics of PHP, including its syntax, commenting,
              variables,  and the  echo  statement.  Understanding  these  fundamental  concepts
              lays the foundation for your PHP programming journey in the context of database
              management.                                                                          Chapter Eight: Databases and Database Management Systems
          FOR ONLINE READING ONLY

              (a) PHP syntax
                 (i)   PHP code is written inside <?php ?> tags. For example: <?php ...code... ?>
                 (ii) Statements in PHP are terminated with a semicolon (;).

                 (iii)  PHP is not case-sensitive, so you can use either uppercase or lowercase letters
                         for language constructs.

              (b) Commenting
                  (i)  Comments in PHP are used to document or temporarily disable parts of the
                     code.
                  (ii) Single-line comments start with // or #. For example: // This is a comment.

                  (iii) Multi-line comments are enclosed between /* and /. For example:
                       /

                       This is a multi-line comment.
                       It can span multiple lines.

                       */

              (c) Variables
                  (i)  Variables are used to store data and give them meaningful names.
                  (ii)   In PHP, variables start with a dollar sign ($), followed by the variable
                      name. For example: $name, $age.

                  (iii)  Variable names can contain letters, digits, and underscores, but they must
                      start with a letter or underscore.

                  (iv)  PHP uses dynamic typing, meaning you don’t need to declare the variable
                      type explicitly.
                  (v)  Assigning a value to a variable is done using the assignment operator (=).
                      For example: $name = “John”;
              (d) The echo statement

                   (i)   The echo statement is used to output text or variables onto the web page.
                   (ii)  To display a string literal, enclose it in quotes (single or double). For
                         example echo “Hello, World!”;

                                                    501
               Student’s Book  Form Five



     Computer Science Form 5.indd   501                                                     23/07/2024   12:35
   505   506   507   508   509   510   511   512   513   514   515