Author: Saim Khalid
-
Indexed Array
In PHP, the array elements may be a collection of key-value pairs or it may contain values only. If the array consists of values only, it is said to be an indexed array, as each element is identified by an incrementing index, starting with “0”. Creating an Indexed Array An indexed array in PHP may…
-
Arrays
An array is a data structure that stores one or more data values having some relation among them, in a single variable. For example, if you want to store the marks of 10 students in a class, then instead of defining 10 different variables, its easy to define an array of 10 length. Arrays in…
-
Continue Statement
Like the break statement, continue is another “loop control statement” in PHP. Unlike the break statement, the continue statement skips the current iteration and continues execution at the condition evaluation and then the beginning of the next iteration. The continue statement can be used inside any type of looping constructs, i.e., for, for-each, while or do-while loops. Like break, the continue keyword is also normally used conditionally. Syntax of Continue Statement The…
-
Break Statement
The break statement along with the continue statement in PHP are known as “loop control statements”. Any type of loop (for, while or do-while) in PHP is designed to run for a certain number of iterations, as per the test condition used. The break statement inside the looping block takes the program flow outside the block, abandoning the rest of iterations that may be…
-
DoWhile Loop
The “dowhile” loop is another looping construct available in PHP. This type of loop is similar to the while loop, except that the test condition is checked at the end of each iteration rather than at the beginning of a new iteration. The while loop verifies the truth condition before entering the loop, whereas in “dowhile” loop, the truth…
-
While Loop
The easiest way to create a loop in a PHP script is with the while construct. The syntax of while loop in PHP is similar to that in C language. The loop body block will be repeatedly executed as long as the Boolean expression in the while statement is true. It allows us to repeat a set of instructions…
-
Foreach Loop
The foreach construct in PHP is specially meant for iterating over arrays. If you try to use it on a variable with a different data type, PHP raises an error. The foreach loop in PHP can be used with indexed array as well as associative array. There are two types of usage syntaxes available − Syntax for Indexed Arrays…
-
For Loop
A program by default follows a sequential execution of statements. If the program flow is directed towards any of earlier statements in the program, it constitutes a loop. The for statement in PHP is a convenient tool to constitute a loop in a PHP script. In this chapter, we will discuss PHPs for statement. Flowchart of a…
-
Loop Types
PHP uses different types of of loops to execute the same code continuously. Loops help to decrease code repetition and optimize programs. Loops allow programmers to save time and effort by writing less code. We use loops to avoid writing the same code repeatedly. Loops are important in web applications for showing numbers, processing data…
-
Switch Statement
In PHP, the switch statement allows many if-else conditions for a single variable. Sometimes you need to compare a variable to multiple values and run separate code for each one. In general, you would write if elseifelse. An excessive number of if-else statements can result in long, difficult-to-read code.Using a switch statement instead of many if-else statements can reduce…