Explain variable manipulation in PHP
Variable manipulation is the process of modifying the value of a variable in PHP. PHP provides
a wide range of operators and functions for variable manipulation, including arithmetic
operators, string operators, and comparison operators.
Here are some examples of variable manipulation in PHP:
1. Arithmetic operators:
PHP provides arithmetic operators for performing basic mathematical operations on
variables. These operators include addition (+), subtraction (-), multiplication (), division (/),
modulus (%), and exponentiation (*).
For example:
$num1 = 10;
$num2 = 5;
// Addition
$result = $num1 + $num2; // $result = 15
// Subtraction
$result = $num1 - $num2; // $result = 5
// Multiplication
$result = $num1 * $num2; // $result = 50
// Division
$result = $num1 / $num2; // $result = 2
// Modulus
$result = $num1 % $num2; // $result = 0
EasyExamNotes.com Explain variable manipulation in PHP
Explain variable manipulation in PHP
// Exponentiation
$result = $num1 ** $num2; // $result = 100000
2. String operators:
PHP provides string operators for manipulating strings. These operators include
concatenation (.), concatenation assignment (.=), and substring (substr()).
For example:
$str1 = "Hello";
$str2 = "world";
// Concatenation
$result = $str1 . " " . $str2; // $result = "Hello world"
// Concatenation assignment
$str1 .= " PHP"; // $str1 = "Hello PHP"
// Substring
$result = substr($str1, 0, 5); // $result = "Hello"
3. Comparison operators:
PHP provides comparison operators for comparing variables. These operators include equal to
(==), not equal to (!=), identical to (===), not identical to (!==), greater than (>), less than
(<), greater than or equal to (>=), and less than or equal to (<=).
EasyExamNotes.com Explain variable manipulation in PHP
Explain variable manipulation in PHP
For example:
$num1 = 10;
$num2 = 5;
// Equal to
$result = ($num1 == $num2); // $result = false
// Not equal to
$result = ($num1 != $num2); // $result = true
// Identical to
$result = ($num1 === $num2); // $result = false
// Greater than
$result = ($num1 > $num2); // $result = true
// Less than
$result = ($num1 < $num2); // $result = false
// Greater than or equal to
$result = ($num1 >= $num2); // $result = true
// Less than or equal to
$result = ($num1 <= $num2); // $result = false
Related posts:
1. Explain interfaces to external system in PHP ?
2. What are the hardware and software requirement of PHP
3. Explain the procedure to repeat code in PHP.
4. What are dynamic variables in PHP? Explain
EasyExamNotes.com Explain variable manipulation in PHP