Page 250 - Computer Software Application TP - Volume 1
P. 250

COMPUTER SOFTWARE APPLICATION - CITS



           EXERCISE 52 : Demonstrate  on Function  and returning

                                     value  from  function,  user  defined
                                     functions,  dynamic functions, variable

                                     scope,  accessing  variable with  the

                                     global statement, Function calls with the
                                     static statement, setting default values

                                     for arguments, Passing  arguments to  a

                                     function  by  value,  Passing  arguments

                                     to a function  by reference, Testing for
                                     function existence


            Objectives

           At the end of this exercise you shall be able to
           •  create and use user defined functions in PHP
           •  check different variable scope in PHP
           •  test the existence of function in PHP.

           Requirements

           Tools/Materials

           •   Computer/Laptop with latest configuration       •  PHP
           •   Operating system: windows 10 or 11              •  Text editor
           •  Apache web server                                •  Web browsers


           Procedure

           TASK 1: Create user defined functions
              1  Open the text editor
              2  Write the following codes
                              <html>
                              <body>
                               <?php
                                  function writeMsg()
                                  {
                         echo “Hello world!”;
                                  }
                                  writeMsg();
                                 ?>
                              </body>
                              </html>
              3  Save the program in C:\Apache24\htdocs in a folder with .php extension
              4  Run the Apache services from windows services
              5  Open the browser and type the following address
                 http://localhost/foldername/
              6  Click the php file to run  and verify the output



                                                           235
   245   246   247   248   249   250   251   252   253   254   255