Assignment Operators Of Php

From the Below Examples We Will Get to know some Basic Examples Of Assignment operators In Php


 <?php

$num1 = 10;

$num2 = 5;


// Simple assignment

$result = $num1;

echo $result . "\n"; // Output: 10


// Addition assignment

$result += $num2;

echo $result . "\n"; // Output: 15


// Subtraction assignment

$result -= $num2;

echo $result . "\n"; // Output: 10


// Multiplication assignment

$result *= $num2;

echo $result . "\n"; // Output: 50


// Division assignment

$result /= $num2;

echo $result . "\n"; // Output: 10


// Modulus assignment

$result %= $num2;

echo $result . "\n"; // Output: 0

?>

In this example, we first declare two variables $num1 and $num2 and assign them values. Then we use various assignment operators to perform arithmetic operations and assign the result to the $result variable. Finally, we use the echo statement to print the result to the screen.

Comments