Showing posts with label Assignment operators PHP example. Show all posts
Showing posts with label Assignment operators PHP example. Show all posts

Tuesday, March 5, 2024

PHP Assignment Operators

 PHP Assignment Operators

PHP Assignment Operators


PHP Assignment Operators

  • Assignment (=)
  • Addition assignment (+=)
  • Subtraction assignment (-=)
  • Multiplication assignment (*=)
  • Division assignment (/=)
  • Modulus assignment (%=)


php Assignment Operators :


Example:-



<?php

// Assignment Operations in PHP

// Addition
$x = 5;
$y = 3;
$x += $y; // Equivalent to: $x = $x + $y;
echo "Addition :  = $x\n";

// Subtraction
$x = 10;
$y = 4;
$x -= $y; // Equivalent to: $x = $x - $y;
echo "Subtraction: = $x\n";

// Multiplication
$x = 6;
$y = 2;
$x *= $y; // Equivalent to: $x = $x * $y;
echo "Multiplication : = $x\n";

// Division
$x = 16;
$y = 4;
$x /= $y; // Equivalent to: $x = $x / $y;
echo "Division : = $x\n";

// Modulus
$x = 17;
$y = 5;
$x %= $y; // Equivalent to: $x = $x % $y;
echo "Modulus : = $x\n";

// Concatenation(for strings)
$str1 = "Hello, ";
$str2 = "World!";
$str1 .= $str2; // Equivalent to: $str1 = $str1 . $str2;
echo "Concatenation : $str1\n";

?>


Assignment Operators php :


Output :-
Assignment operators php/output



READ MORE