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

COMPUTER SOFTWARE APPLICATION - CITS




           TASK 3: Setting default values for arguments

              1  Open the text editor
              2  Write the following codes
                              <html>
                              <body>
                              <?php
                                 function setHeight(int $minheight=100)
                                 {
                    echo “The height is : $minheight <br>”;
                              }


                                 setHeight(350);
                                 setHeight();
                              setHeight(135);
                             ?>
                            </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






















           TASK 4: Passing arguments to a function by reference

              By default, function arguments are passed by value (so that if the value of the argument within the function
              is changed, it does not get changed outside of the function). To allow a function to modify its arguments, they
              must be passed by reference.
              To have an argument to a function always passed by reference, prepend an ampersand (&) to the argument
              name in the function definition:
              1  Open the text editor
              2  Write the following codes
                              <html>
                              <head>



                                                           237

                               CITS : IT & ITES - Computer Software Application - Exercise 52
   247   248   249   250   251   252   253   254   255   256   257