Blog

  • Home
  • PHP
  • Conditions and Loops in PHP

Conditions and Loops in PHP

  • (4.0)
  • | 1634 Ratings

CONSTANT

DEFINE:-

Define is the pre-defined key-word in php. This will take two arguments. The first argument being the constant identifier which identifier its second argument value. We can pass third argument as Boolean to make case in-sensitive

CONSTANT

Checkout PHP Interview Questions

CONDITIONS

Conditional statements are used to perform different actions based on different conditions.

IF CONDITION:-

IF CONDITIONIF CONDITION Example

WHILE CONDITION:-

The while loop executes a block of code while a condition is true

SAP Information Map

OUTPUT:-

The number is 1
The number is 2
The number is 3
The number is 4
The number is 5

Related Page: Cookies, Sessions And Buffer In PHP

DO-WHILE CONDITION:- 

The do…while statement will always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true.

DO-WHILE CONDITION

Example

The example below defines a loop that starts with i=1. It will then increment i with 1, and write some output. Then the condition is checked, and the loop will continue to run as long as i is less than, or equal to 5:

DO-WHILE CONDITION Example

FOR LOOP:-

Loops execute a block of code a specified number of times, or while a specified condition is true. The for loop is used when you know in advance how many times the script should run.

Related Page: Headers, Downloading And File Uploading In PHP

FOR EACH:-

for each is usefull for all non-sequence data of an array. Associative array ,numerical array object data of an array
The general syntax is
foreach (arrayName as arr[value]))
{
echo arr [value];
}
Another syntax is
foreach (arrayname as key=>value)
{
echo key’-‘value         (or)        echo “key-value”;   }

Ex: -foreach.php


Subscribe For Free Demo

Free Demo for Corporate & Online Trainings.

Ravindra Savaram
About The Author

Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.


DMCA.com Protection Status

Close
Close