Table of Contents Introduction Local Variable Scope Global Variable Scope The global Keyword Static Variables Introduction The scope of a variable is the part of the PHP script where the variable can be referenced or used. There are three different variable scopes: local scope global scope static scope Local Variable...
Table of Contents Introduction Syntax of a Function Built-in Functions Custom Functions Default Argument Values Returning Values from Functions Returning a Single Value Returning Multiple Values Passing Arguments by Reference Introduction A function is a set of statements that perform a particular task (and optionally...
Table of Contents Introduction The break Statement The continue Statement Introduction Both break and continuecan be used in a loop to “break out” of the loop or current iteration. break ends execution of the current for, foreach, while, do-while or switch structure. continue is used to skip the rest of the current...
Table of Contents Introduction Syntax of the foreach Loop Using the foreach Loop Introduction The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable....
Table of Contents Introduction Syntax of the for Loop Using the for Loop Introduction The for loop loops through a block of code a specified number of times. It is used when we know in advance how many times the code block should run. Syntax of the for Loop The syntax of the for loop is given as: Syntax The for loop....
Table of Contents Introduction Syntax of the do...while Loop Using the do...while Loop Introduction do-while loops are very similar to while loops except that the truth expression is checked at the end of each iteration instead of at the beginning. The main difference from the regular while loops is that the first...
Table of Contents Introduction Syntax of the while Loop Using the while Loop Introduction Often, you want the same block of code to run over and over again a certain number of times. Instead of adding the same chunk of code into your script, we can use loops. Loops are used to execute the same block of code again and...
Table of Contents Introduction Syntax of the match Expression Using the match Expression Introduction The match expression branches evaluation based on an identity check of a value. Similar to a switch statement, a match expression has a subject expression that is compared against multiple alternatives. However, unlike...
Table of Contents Introduction Why the switch Statement? Syntax of the switch Statement Using the switch Statement Introduction The switch statement is similar to a series of if statements on the same expression. This is applicable to the case where we may want to test the same expression with many different values,...
Table of Contents Introduction The if Statement The if...else Statement The if...elseif...else Statement Introduction In this article, we discuss program flow control. The if construct is one of the most important tools of PHP when its come to conditional execution of code fragments. The if construct comes in different...