Category: PHP

Associative Arrays in PHP

Associative arrays are object-indexed collection of items.  They are also known as key-value pairs where index act as key and its item act as value.   A simple array is used when you want to create collection of items and you want to store them in a certain order.  An associative array is used when you

Arrays in PHP

Arrays are nothing more than an integer-indexed collection of items.  An index of an array always starts from 0.  The collection of items in an array could be of any data type like string, int, float or even an another array which forms a nested array.  The length of an array is not fixed because

Logical Operators in PHP with Example

We have seen how comparison operators work in PHP with conditional statements.  Comparison operators compare 2 values and return boolean value (true or false).  But we do encounter some scenarios where we want to make our judgement based on 2 boolean values returned by 2 conditions.  In such scenario, logical operators comes into play.  Most

Conditional Statements in PHP with Example

In PHP, if and elseif statements are conditional statements.  They work with comparison operators.  Conditional statements form a block where further code execution depends upon result of a condition.  The condition will return a boolean value (true or false). If statement is always the first statement in the series of conditional statements.  If first statement

Comparison Operators in PHP

In PHP, when we want to compare 2 values, we make use of comparison operators.  These comparison operators are basically used with conditional statements and will return a boolean value (true or false).  Most commonly used comparison operators are given below. Operator Meaning $a == $b $a is equal to $b $a != $b $a