0% found this document useful (0 votes)
2 views

PHP_Operators_Activity

The document provides examples of various PHP operators including arithmetic, assignment, comparison, logical, and increment/decrement operators. Each section contains PHP code snippets demonstrating how these operators work with different variables. The examples illustrate the output of operations and the effects of operator usage in PHP programming.

Uploaded by

Night Wolf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PHP_Operators_Activity

The document provides examples of various PHP operators including arithmetic, assignment, comparison, logical, and increment/decrement operators. Each section contains PHP code snippets demonstrating how these operators work with different variables. The examples illustrate the output of operations and the effects of operator usage in PHP programming.

Uploaded by

Night Wolf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PHP Operators Activity

I. Arithmetic Operators

<?php
$a = 10;
$b = 3;
echo $a + $b;
?>
<?php
$x = 15;
$y = 5;
echo $x - $y;
?>
<?php
$m = 4;
$n = 6;
echo $m * $n;
?>
<?php
$p = 20;
$q = 4;
echo $p / $q;
?>
<?php
$r = 9;
$s = 2;
echo $r % $s;
?>

II. Assignment Operators

<?php
$a = 5;
$b = 3;
$c = 2;
$a += $b;
$b *= $c;
c -= $a;
echo $a . ', ' . $b . ', ' . $c;
?>
<?php
$x = 10;
$y = 4;
$z = 6;
x -= $y;
z += $x;
y %= $z;
echo $x . ', ' . $y . ', ' . $z;
?>
<?php
PHP Operators Activity

$m = 8;
$n = 2;
o = 5;
n *= $m;
m /= $o;
o += $n;
echo $m . ', ' . $n . ', ' . $o;
?>
<?php
i = 12;
j = 3;
k = 7;
j += $i;
k *= $j;
i %= $k;
echo $i . ', ' . $j . ', ' . $k;
?>
<?php
$p = 9;
$q = 5;
r = 4;
p *= $q;
q -= $r;
r += $p;
echo $p . ', ' . $q . ', ' . $r;
?>

III. Comparison Operators

<?php
$a = 5;
$b = "5";
var_dump($a == $b);
?>
<?php
$a = 7;
$b = "7";
var_dump($a === $b);
?>
<?php
$a = 10;
$b = 8;
var_dump($a != $b);
?>
<?php
$x = 4;
$y = 9;
var_dump($x > $y);
?>
PHP Operators Activity

<?php
$p = 12;
$q = 12;
var_dump($p <= $q);
?>

IV. Logical Operators

<?php
$is_raining = true;
$has_umbrella = false;
var_dump($is_raining && $has_umbrella); // Can go outside?
?>
<?php
$is_hungry = false;
$has_food = true;
var_dump($is_hungry || $has_food); // Will eat?
?>
<?php
$has_ticket = false;
$knows_security = false;
var_dump($has_ticket || $knows_security); // Can enter event?
?>
<?php
$studied = true;
$slept_well = true;
var_dump($studied and $slept_well); // Ready for exam?
?>
<?php
$has_cash = true;
$has_card = true;
var_dump($has_cash xor $has_card); // Only one mode of payment?
?>

V. Increment/Decrement Operators

<?php
$a = 5;
echo ++$a;
?>
<?php
$b = 10;
echo $b++;
?>
<?php
$c = 7;
echo --$c;
?>
<?php
PHP Operators Activity

$d = 3;
echo $d--;
?>
<?php
$e = 8;
echo $e;
$e++;
echo $e;
?>

You might also like