Register|Login

Have a question? Click here to ask the community.

Tutorial 10 – Operators

| In: 10. Operators | 9,730 views

Video Tutorial

Part 1:


Part 2:


Video Source Code

index.php File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// File Description: PHP Operators Tutorial
 
////Arithmetic Operators
$value1 = 5;
$value1 = $value1 + 5;
echo "Addition Value: $value1 <br>";
 
// Modulus %
$value2 = 7;
$value2 = $value2 % 2;
echo "Modulus Value: $value2 <br>";
 
//Increment
$value3 = 5;
$value3++;
echo "Increment Value: $value3 <br>";
 
//Decrement
$value4 = 100;
$value4--;
echo "Decrement Value: $value4 <br>";
 
////Assignment Operators
$a = 6;
$b = 4;
$a = $b; 
echo "A now contains: $a";
 
$a += $b; // $a = $a + $b;
$a -= $b; // $a = $a - $b;
 
 
////Comparison Operators
$one = 1;
$two = 2;
 
//True or False
 
//Is Equal To ==
$one == $two //return FALSE
$one == 1 //return TRUE
 
//Is Not Equal To !=, <>
$one != $two //return TRUE
$one <> $two //return TRUE
 
// Is Greater or Less Than >, <
$one > $two // return FALSE
$one < $two //return TRUE
 
// Is Greater or Less Than or Equal To >= , <=
$one >= $two //return FALSE
$one <= $two //return TRUE
 
////Logical Operators
 
// AND Operator &&
($one > 0 && $two > $one) // return true
// (true AND true) // return true
// (true && true) // return true
// (true && false) // return false
// (false && true) // return false
// (false && false) // return false
 
// OR Operator ||
($one < 0 || $two > $one) // return true
// (false || true) //return true
// (false || false) //return false
// (true || false) // return true
// (true || true) // true
 
// NOT Operator !
!($one == $two) //return TRUE
//!(true) //return FALSE
//!(false) //return TRUE
?>

Comment Form

You must be logged in to post a comment.