File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Conditional Operators in PHP</title>
7
+ </head>
8
+ <body>
9
+
10
+ <?php
11
+
12
+ # Conditional Operator is used to check condition
13
+ # ?: Ternary or Conditional Operator
14
+ # If condition is true, first statement is returned else second
15
+
16
+ echo "<p>Using Conditional Operators in PHP</p> " ;
17
+
18
+ # Creating variables
19
+ $ a =9 ;
20
+
21
+ # Using operator ?:
22
+
23
+ # We cannot use echo in ternary operator
24
+ # ($a>8)? echo "a is greater than 8."; : echo "a is greater than 8.";
25
+ # This will give the following error
26
+ # Parse error: syntax error, unexpected token "echo" in C:\xampp\htdocs\PHP Programming\Operators\Conditional-Operators.php on line 22
27
+
28
+ # Operator returns argument we can print that
29
+ echo "<p>Returning Argument from Operator ?:</p> " ;
30
+ echo ($ a >8 )?"Variable a is greater than 8. " :"Variable a is lesser than 8. " ;
31
+
32
+ # Storing return value in a variable
33
+ $ result =($ a >8 )?"Variable a is greater than 8. " :"Variable a is lesser than 8. " ;
34
+ echo "<p>Storing return value in a variable.</p> " ;
35
+ echo "<p>Result is: " ,$ result ,"</p> " ;
36
+
37
+ ?>
38
+
39
+ </body>
40
+ </html>
You can’t perform that action at this time.
0 commit comments