Follow Star

Control Structures else

بناء الجملة .

1. if(){} else(){} code .

1
2
if (Conditional) code; else{code};
if (Conditional){code}; else{code};

2. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
<?php
$a = 1 + 5;
$b = 1 + 6;

if ($a !== $b) {
  echo "a !== $b";
} else {
  echo "a == $b";
}
?>

3. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
11
<?php
$knows1 = 1;
$knows2 = 2;
if ($knows1 > $knows2)
echo "Hlloo Hier ist knows1";
else{

echo "knows1 ist < knows2 ";

}
?>

4. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
11
12
  
<?php
$knows1 = 100600;
$knows2 = 100600;
if ($knows1 < $knows2)
echo "$knows1 < $knows2";
else{

echo "xxxxxxxx";
}
//xxxxxxxx
?>

5. if(){} else(){} code .

1
2
3
4
5
6
<?php
if ($a !== null): ?>
<p style="color:red;">I am red</p>
<?php else: ?>
<h1>$a !== null</h1>
<?php endif; ?>

6. if(){} else(){} code .

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
<!DOCTYPE html>
<html>
<body>
<?php
$a=5;
if ($a == 5): ?>
<h2>if(){} else(){} code</h2>

<table style="width:100%">
  <tr>
    <th>1</th>
    <th>2</th>
    <th>2</th>
  </tr>
  <tr>
    <td>knows1</td>
    <td>knows2</td>
    <td>knows3</td>
  </tr>
  <tr>
    <td>562</td>
    <td>56656</td>
    <td>65656</td>
  </tr>
  <tr>
    <td>54656</td>
    <td>56565</td>
    <td>656565</td>
  </tr>
</table>
  <?php else: ?>
<h1 style="background-color:Tomato;">knows1</h1>
<?php endif; ?>
</body>
</html>

7. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$a  = 0;
$b = 1;

if ( $a == 1) {
    $a = 'knows1';
}elseif($b !== 1) {

echo $b = "knows2";    

}else {
    echo $c = "knows3 ";
}

?>

8. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
  $knows1="Hallo";
  $knows2="Hallo";

  if ($knows1<$knows2)
     {
    echo " es ist $knows1 < $knows2 ";
  }elseif ($knows1>$knows2) {

  echo  "es ist $knows1 > $knows2";

  }else{

  echo "so get else";

  }
?>

9. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
<?php
$b = true;
$c = true;
if($a !== null) { echo "knows1"; }
elseif($b == $a) { echo "knows2"; }
elseif($c === $m) { echo "knows3"; }
else { echo 5154515 % 10001551215; }
?>
<?php

10. if(){} else(){} code .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$b = true;
$c = true;
if($a !== null) { echo "knows1"; }
elseif($b == $a) { echo "knows2"; }
elseif($c === $m) { echo "knows3"; }
else { echo 5154515 % 10001551215; }
////////
echo "<br>";
if($a == null) { echo "knows1"; }
elseif($b == $a) { echo "knows2"; }
elseif($c === $m) { echo "knows3"; }
else { echo 5154515 % 10001551215; }
////////////
echo "<br>";
if($a !== null) { echo "knows1"; }
elseif($b !== $a) { echo "knows2"; }
elseif($c === $m) { echo "knows3"; }
else { echo 5154515 % 10001551215; }
?>
Control Structures      
if      
else      
elseif/else if      
Alternative syntax for control structures      
while      
do-while      
for      
foreach      
break      
continue      
switch      
declare      
return      
require      
include      
require_once      
include_once      
goto      

Tags:

Categories:

Updated:

Comments