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 Data Type and Variable Explanation

Data type and variable are frequently used topics in PHP programming. So, PHP programmer should have basic and clear concept on PHP data types and variables. Various types of data are used in PHP programming and variables usually hold these data in memory for a certain time. In my previous article I discussed PHP basic program with example and in this article I will discuss basic concept on PHP data types and variables. PHP Data Types Like other programming languages, various types of data are used in PHP programming language. These data can be categorized into 8 types. The following table is a summarization of the various data types used in PHP Programming Language. No. Data Types Description 1 Integer Real number without decimals. Such as 1, 5, 100, 1000 and so on 2 Float Real number with decimals. Such as 35.5, 100.10 and so on. 3 String Sum of several characters that means a word, a sentence or several sentences 4 Boolean Either true or false value. True represents 1 and false represents 0. 5 NULL This is a special data type in PHP which has no data value. 6 Array Various types of data are kept within this […]

Continue reading