Function Call by Value and Call by Reference in PHP

More than thousands of built-in functions prove the power of PHP Language. Besides built-in function PHP allows to create user defined function. How to create user defined function with example was explained in previous article. I also explained how to use variables inside a PHP function properly. Function call by value and call by reference is another important terms in PHP programming. So, in this article I will discuss how to call PHP function by value and by reference with example Function call by value in PHP If any PHP function accepts parameters, we usually send arguments when function is called. If we send values as arguments when function is called, it is known as function call by value. With function call by value technique, the value of a variable that is sent as arguments keeps unchanged although it is altered in function body. We usually use function call value technique most of our PHP programs. The following code is an example of function call by value in PHP. Output Inside function: 20 Outside function: 10. In the above program, the addTen() function is being called with a variable named $num. After calling the function, the variable is being printed […]

Continue reading


PHP Variable Usage inside of Function

Besides more than thousands of built-in functions PHP provides facility to define custom/user defined function. Basic expression to define a custom function and calling a custom function was discussed in previous article. Variable plays an important role in PHP function. PHP function typically has local, global and static variables. A PHP programmer should know how to use local, global and static variable in PHP function. So, in this article I will discuss how to define and use local, global and static variables inside a PHP function. Variables in PHP Function According to variable scope and usage in PHP function, variable can be categorized into the following three types. PHP local variable in function PHP static variable in function PHP global variable in function PHP Local Variable in Function Local variables are those variables which are defined and used within a PHP function. So, if we define a variable within a PHP function, the variable will be local variable. After executing the function, defined local variables will be erased from the memory. So, we cannot reuse local variable outside of a function. If we use a local variable outside of a function, PHP compiler will show an error message.   The following […]

Continue reading


PHP Function Explanation

Real power of a programming language comes from its functions. More than 1000 built-in functions defined in PHP language prove the power of PHP language. Besides built-in function PHP has capability to declare user defined function like other programming language. So, PHP becomes a dominating programming language having a number of built-in functions and user defined function capability. A newbie PHP programmer should have enough skill on PHP functions along with other PHP basic items because PHP program frequently uses built-in function as well as user defined function. In my previous article I explained PHP loop statements elaborately and in this article I will discuss details on PHP functions.     PHP Function A function is a block of statement that takes one or more input values in form of argument and does some processing and then returns a value. PHP function can be divided into the following two categories. Built-in function User defined function PHP Built-in Function Built-in functions are those functions whose definition is predefined in PHP. More than thousands of built-in functions are present in PHP. Built-in function has predefined arguments and return that we have to know before usage. If you do practice regularly, you will able to […]

Continue reading