SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP

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.

Conditional checking with if else

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.

Loop using for each

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.

While loop

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.

Do while loop

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 ?

Switch statement

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.

How to check the presence of a variable

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 :


Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer