PHP Functions

PHP Functions What is function? Function is a block of code or statement that can be used many times in a program. Function will be executed by a call to the function. Function will not execute immediately when a page loads. A Function is a reusable piece of code. We will write it once and […]

The PHP while and do…while Loop

The PHP while Loop The while loop executes a block of code as long as the specified condition is true. A “While” Loop is used to repeat a specific block of code an unknown number of times, until a condition is met. For example, if we want to ask a user for a number between […]

PHP for and foreach loop

Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types. for foreach while do…while The for loop is used when we loops through a block of code a specified number of times. It means, we know in advance how many times the […]

PHP Switch Statement

Switch Statement If we have many conditions, PHP switch statement is a more efficient way of doing this. With the help of the switch statement we can check for all these conditions at once. Switch statement is used to avoid many blocks of if..elseif..else code. Syntax: switch (expression) { case label1: this code will be […]

PHP if…else…elseif Conditional Statment

if Statement We use if statements in PHP when we want our program to execute a block of code only if a particular condition is true. It means, if statement is used to execute some code only if a specified condition is true. Syntax: if (condition) { this code will be executed if condition is […]

PHP Operators

An operator is something that takes one or more values and give another value. We can easily understand as expression 4 + 2 is equal to 6. Here 4 and 2 are called operands and + is called operator. This chapter shows the different operators that can be used in PHP scripts. Arithmetic Operators Comparison […]

PHP Constants

A constant is an identifier (name) for a simple value. A constant’s value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores (no $ […]

PHP Trait

As of PHP 5.4.0, PHP implements a method of code reuse called Traits Traits are used for code reusing in PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the […]