<?php
// For each loops
echo “<h3>For each loops</h3>”;
echo “Welcome to the world of foreach loops <br>”;
$arr = array(“bananas”, “apples”, “banner”, “bread”);
// for ($i=0; $i < count($arr); $i++){
//     echo $arr[$i];
//     echo “<br>”;
// }
foreach ($arr as $value) {
    echo ” $value <br>”;
}
// do while loop
echo “<h3>Do While Loop</h3>”;
$i=89;
 do{
    echo “$i <br>”;
 } while ($i<5);
// For Loops
echo “<h3>For Loops</h3>”;
for ($index=1; $index < 10; $index+=3){
    echo “The number is $index <br>”;
}
echo “<br>”;
for($index=1; $index< 10; $index+=2){
    echo “The number is $index <br>”;
}
// Avoid running into infinite loops
// for ($i=0; $i < 87;) {
//     echo “$i<br>”;
// }
// While loops
echo “while loops in php”;
echo “<br>”;
$i = 0;
while($i<5){
    echo $i+1;
    echo “<br>”;
    $i++;
}
// Switch Case
echo “<h3>Switch Case</h3>”;
// $age = 56;
// switch($age){
//     case 12:
//         echo “You are 12 years old”;
//         break;
//     case 45:
//         echo “You are 45 years old”;
//         break;
//     case 56:
//         echo “You are 56 years old boy”;
//         break;
//     default:
//         echo “Your age is weird”;
//         break;
// }
// if else condition
echo “<h3>If Else Condition</h3>”;
// $c = 658;
// $d = 9;
// if($c > 78){
//     echo “a is greater than 78”;
// }
// else{
//     echo “a is not greater than 78”;
// }
// $age = 4;
// If else ladder
// if ($age>18){
//     echo “You can drink water with chai and biscuit”;
// }
// elseif($age>13){
//     echo “You can drink chai only with water”;
// }
// else{
//     echo “You can drink water only”;
// }
// if ($age>18){
//     echo “You can drink water with chai and biscuit”;
// }
// echo “<br>”;
// if($age>13){
//     echo “You can drink chai only with water”;
// }
// else{
//     echo “You can drink water only”;
//  }
echo “<br>”;
// echo “Done”;
echo “<br>”;
// $age = 65;
// if($age>78){
//     echo “a is greater than 78”;
// }
// else{
//     echo “a is less than 78”;
// }
echo “<br>”;
// $age = 25;
// if($age>18){
//     echo “You can drink water with chai and biscuit”;
// }
// elseif($age>13){
//     echo “You can drink water with chai”;
// }
// else{
//     echo “You can drink only water”;
// }
// Drive the car
$age = 66;
if($age>65){
    echo “You can not drive the Car, because your age is greater than 65 <br>”;
}
elseif($age>25){
    echo “You can drive the car, because your age is greater than 25 <br>”;
}
else{
    echo “You can not drive the car, because your age is less than 25 <br>”;
}
echo “Done”;
echo “<br>”;
echo “<br>”;
// Pakistan Chase the target
$score = “324”;
if($score>323){
    echo “Team A won the match”;
}
elseif($score>322){
    echo “Team A lost the match”;
}
elseif($score=322){
    echo “Match Draw”;
}
else{
    echo “Done”;
}
// Operators in PHP
/*
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operator
4. Logical Operators
*/
// 1. Arithmetic Operators
echo “<h3>1. Arithmetic Operators</h3>”;
echo “<br>”;
$a = 45;
$b = 8;
echo “For a + b, the result is ” . ($a + $b) . “<br>”;
echo “For a – b, the result is ” . ($a – $b) . “<br>”;
echo “For a * b, the result is ” . ($a * $b) . “<br>”;
echo “For a / b, the result is ” . ($a / $b) . “<br>”;
echo “For a % b, the result is ” . ($a % $b) . “<br>”;
echo “For a ** b, the result is ” . ($a ** $b) . “<br>”;
echo “<br>”;
// 2. Assignment Operators
echo “<h3>2. Assignment Operators</h3>”;
echo “<br>”;
//$x = $a;
//echo “For x, the value is “. $x . “<br>”;
// add addition amount with variable amount
$a += 6;
echo “For a, the value is “. $a . “<br>”;
$a -= 6;
echo “For a, the value is “. $a . “<br>”;
$a *= 6;
echo “For a, the value is “. $a . “<br>”;
$a /= 6;
echo “For a, the value is “. $a . “<br>”;
$a %= 5;
echo “For a, the value is “. $a . “<br>”;
echo “<br>”;
// 3. Comparison Operators
echo “<h3>3. Comparison Operators</h3>”;
echo “<br>”;
$x = 777;
$y = 78;
echo “For $x == $y, the resutl is “;
echo “<br>”;
echo var_dump($x == $y);
echo “<br>”;
echo var_dump($x > $y);
echo “<br>”;
echo var_dump($x < $y);
echo “<br>”;
echo var_dump($x == $y);
echo “<br>”;
echo “<br>”;
$u = 78;
$v = 78;
echo “For $u == $v, the resutl is “;
echo “<br>”;
echo var_dump($u == $v);
echo “<br>”;
echo var_dump($u > $v);
echo “<br>”;
echo var_dump($u < $v);
echo “<br>”;
echo var_dump($u == $v);
echo “<br>”;
echo “<br>”;
echo “For $u >= $v, the resutl is “;
echo “<br>”;
echo var_dump($u >= $v);
echo “<br>”;
echo var_dump($u <= $v);
echo “<br>”;
echo “<br>”;
// 4. Logical Operators
echo “<h3>4. Logical Operators</h3>”;
$m = false;
$n = false;
echo “For m and n, the result is “;
echo var_dump($m and $n);
echo “<br>”;
echo “For m && n, the result is “;
echo var_dump($m && $n);
echo “<br>”;
echo “For m or n, the result is “;
echo var_dump($m or $n);
echo “<br>”;
echo “For m || n, the result is “;
echo var_dump($m || $n);
echo “<br>”;
//Not Operators
echo “<h3>Not Operators</h3>”;
echo “For !m, the result is “;
echo var_dump(!$m);
echo “<br>”;
//String functions
echo “<h3>String Function</h3>”;
$name = “muneer is the good boy”;
echo $name;
echo “<br>”;
echo “<br>”;
// If you want to add two strings, so use “.” “dot operator”.
echo “The length of ” . “my string is ” . strlen($name);
echo “<br>”;
echo str_word_count($name);
echo “<br>”;
echo “<br>”;
echo strrev($name);
echo “<br>”;
echo strpos($name, “good”);
echo “<br>”;
echo str_replace(“muneer”, “Jamil”, $name);
echo “<br>”;
echo str_repeat($name, 3);
echo “<br>”;
// <pre> means, show as it is
echo “<pre>”;
echo rtrim(”  This is a good boy  “);
echo “<br>”;
echo ltrim(”  This is a good boy  “);
echo “</pre>”;
?>
<?php echo “hello world”;
echo ” <br>”;
/*
php data types
1- String
2- Integer
3- Float
4- Boolean
5- Object
6- Array
7- Null
*/
// String – sequance of Characters
echo “<h3>String</h3>”;
$name = “Muneer<br>”;
$friend = “Jamil”;
echo “$name $friend”;
// Integer – non decimal number
echo “<h3>Integer</h3>”;
$income = 455;
$debts = -655;
echo “$income”;
echo ” <br>”;
echo “$debts”;
// Float – Decimal point number
echo “<h3>Float</h3>”;
$income = “344.5”;
$debts = “45.5”;
echo “$income”;
echo ” <br>”;
echo “$debts <br>”;
// Boolean – Can be either true or false
echo “<h3>Boolean</h3>”;
$x = true;
$is_friend = false;
echo var_dump($x);
echo ” <br>”;
echo var_dump($is_friend);
echo ” <br>”;
// Object –
//Employee is a class —> harry can be one object
// Array – Used to store multiple values in a single variable
echo “<h3>Arrays</h3>”;
$friends = array(“kashif”, “sajid”, “kamal”, “Raju”);
echo var_dump($friends);
echo “<br>”;
echo var_dump($friends[0]);
echo “<br>”;
echo var_dump($friends[1]);
echo “<br>”;
echo var_dump($friends[2]);
echo “<br>”;
echo var_dump($friends[3]);
echo “<br>”;
//echo var_dump($friends[4]); will throw an error as the size of array is 4
// Null
echo “<h3>Null</h3>”;
$name = NULL;
echo var_dump($name);
?>