Loops & program structure of PHP scripts
PHP has some basic programming structure for developing scripts. There is conditional checking to evaluate true of false of a condition, there are loops with conditions and counters and we can check different variables by using simple functions. We can keep a commonly used code blocks inside a function and then call and use them when ever required. All these are basic building blocks of developing a PHP application.
As PHP has more similarity with C language so it has similar for, while, do loops and other functions.
We will learn how this basic flow of PHP language works with example in every section.
We can check condition of any variable or any data by using if condition. This if condition checks TRUE or FALSE and accordingly it allows the blocks to execute.
We can loop through a set of code by keeping them inside a for each loop. We can specify the jump in increment or decrement of counter in each looping.
Here before executing the code inside the loop the condition is checked first. If the condition is TRUE or satisfied then the code inside the loop is executed.
What is the difference between while loop and do while loop? Which one to use in what conditions, when the condition is checked for executing the code inside loop ?
When we know one of the choice of a option is going to match and rest of the options are not going to match once a options is meet then we should go for switch statement then repeated use of if else conditions.
PHP function isset is used to check the existence of a variable before using it. This is required in different conditions where processing the script by a non existence variable can create problem.
Be the first to post comment on this article :