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


Monday, March 4, 2024

PHP comparison operators


PHP comparison operators

PHP Comparison operator

 

Comparison Operators:

  • Equal (==)
  • Identical (===)
  • Not equal (!= or <>)
  • Not identical (!==)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

php comparison operators 

Example :-

<?php
$a=10;
$b=5;
$c=20;
$d=20;
var_dump($a < $c); //true
echo"<br>";
var_dump($a < $b);
echo"<br>";
var_dump($a<=$c);//t
echo"<br>";
var_dump($b>$c);//f
echo "<br>";
var_dump($c>=$d);//true
echo "<br>";
var_dump($c==$d);//t
echo"<br>";
var_dump($a != $d);//t
?>


php comparison operators 

OUTPUT :-

bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)


READ MORE


PHP introduction

PHP variable

PHP operators

PHP Data type

PHP logical operators

PHP Arithmetic Operators

PHP Assignment Operators

PHP string operators


PHP operators

PHP operators

PHP operators


PHP operators 

  1. 1] Arithmetic Operators:

    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
    • Modulus (%)
    • Exponentiation (**)
  2. 2] Assignment Operators:

    • Assignment (=)
    • Addition assignment (+=)
    • Subtraction assignment (-=)
    • Multiplication assignment (*=)
    • Division assignment (/=)
    • Modulus assignment (%=)
  3. 3] Comparison Operators:

    • Equal (==)
    • Identical (===)
    • Not equal (!= or <>)
    • Not identical (!==)
    • Greater than (>)
    • Less than (<)
    • Greater than or equal to (>=)
    • Less than or equal to (<=)
  4. 4] Logical Operators:

    • AND (&& or and)
    • OR (|| or or)
    • NOT (! or not)
    • XOR (exclusive OR) (xor)
  5. 5] Increment/Decrement Operators:

    • Increment (++)
    • Decrement (--)
  6. 6] String Operators:

    • Concatenation (.)
    • Concatenation assignment (.=)
  7. 7] Array Operators:

    • Union (+)
    • Equality (==)
    • Identity (===)
    • Inequality (!= or <>)
    • Not identical (!==)
  8. 8] Ternary Operator:

    • Syntax :-
  9. (condition) ? expression1 : expression2;

it works:

  • 1] If the condition evaluates to true, the expression1 is executed.
  • 2] If the condition evaluates to false, the expression2 is executed.
READ MORE