Page 101 - Open Soource Technologies 304.indd
P. 101

Unit 4: Functions



            4.8 Summary                                                                           Notes

               •  A function call is a piece of code that tells your program to “call in” the built-in function
                 whenever you need it. The second type of function is the user defined function. These are
                 the functions that you write yourself.

               •  Unlike PHP variable names, PHP function names are case insensitive. It is however
                 recommended to remain rigorous when naming and calling any PHP object.
               •  The function takes two arguments, $left and $right. Using the concatenation operator, the
                 function creates a combined string in the variable$combined_string.
               •  The variables used in PHP functions can be of three types: locals, globals and statics. Any
                 variable defined inside a function is by default limited to the local function scope, is available
                 only in the code within that function.
               •  PHP supports the concept of variable functions. This means that if a variable name has
                 parentheses appended to it, PHP will look for a function with the same name as whatever
                 the variable evaluates to, and will attempt to execute it.

            4.9 Keywords

            Default parameters: Default parameters enable you to specify a default value for function
            parameters that are not passed to the function during the function call.
            Function: A function call is a piece of code that tells your program to “call in” the built-in function
            whenever you need it.
            Global variables: A global variable can be accessed in any part of the program. If you want to
            use inside a function a variable defined outside it, that variable must be explicitly declared to be
            global in the function.
            Static variables: A static variable exists only in a local function scope, but it does not lose its value
            when program execution leaves this scope.


                          1.  Develop a PHP program to add two numbers with the help of function.
                          2.  Create a PHP program to concatenate two strings.


            4.10 Review Questions

               1.  What do you mean by function? How does it define in PHP?

               2.  How do we call a function in PHP?
               3.  Explain the user defined function with example.
               4.  What is the variable scope in PHP?
               5.  Differentiate between local and global scope of variables.

               6.  What is the function parameters used in PHP?
               7.  Differentiate between pass by value and pass by reference parameters.
               8.  Explain the return values in PHP.

               9.  What are the variable functions?
              10.  How many categories of PHP functions are there?


                                             LOVELY PROFESSIONAL UNIVERSITY                                    95
   96   97   98   99   100   101   102   103   104   105   106