PHP Epressions and types of expressions.html

sontibhanuprasad 6 views 10 slides Oct 26, 2025
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

PHP Epressions and types of expressions


Slide Content

Expressions In PHP, an expression is a combination of variables, constants, operators, and function calls that evaluates to a value. Expressions can be simple or complex and are fundamental in performing computations, making decisions, and manipulating data.

Arithmetic Expressions Arithmetic expressions perform mathematical operations and return a numeric value. Operators : +, -, *, /, % Example : $ a = 10; $b = 5; $sum = $a + $b; // 15 $difference = $a - $b; // 5 $product = $a * $b; // 50 $quotient = $a / $b; // 2 $modulus = $a % $b; // 0

String Expressions String expressions manipulate text data, including concatenation. Operators : . (concatenation) Example : $ firstName = "John"; $ lastName = "Doe"; $ fullName = $ firstName . " " . $ lastName ; // "John Doe"

Comparison Expressions These expressions compare two values and return a boolean result (true or false). Operators : ==, ===, !=, !==, <, >, <=, >= Example : $x = 10; $y = 20; $ isEqual = ($x == $y); // false $ isIdentical = ($x === $y); // false $ isGreater = ($x > $y); // false

Logical Expressions Logical expressions combine boolean values and return a boolean result. Operators : && (AND), || (OR), ! (NOT) Example : $ isAdult = true; $ hasPermission = false; $result = $ isAdult && $ hasPermission ; // false

Assignment Expressions Assignment expressions assign values to variables. You can also use shorthand operators. Example : $ a = 5; // Simple assignment $a += 3; // Equivalent to $a = $a + 3; (Addition assignment) $a *= 2; // Equivalent to $a = $a * 2; (Multiplication assignment

Increment and Decrement Expressions These expressions increase or decrease a variable's value by one. Example : $ count = 10; $count++; // Increment: $count becomes 11 $count--; // Decrement: $count becomes 10 again

Array Expressions PHP allows the creation and manipulation of arrays. Example : $ fruits = array("apple", "banana", "cherry"); $ firstFruit = $fruits[0]; // "apple"

Ternary Operator The ternary operator is a shorthand for an if-else statement. Example : $ age = 18; $message = ($age >= 18) ? "Adult" : "Minor"; // "Adult"

Function Call Expressions Calling a function is an expression that evaluates to the return value of that function. Example : function add($x, $y) { return $x + $y; } $result = add(5, 10); // $result is 15
Tags