diff --git a/01.print.php b/01.print.php new file mode 100644 index 0000000..4aa87ff --- /dev/null +++ b/01.print.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/02.iterators.php b/02.iterators.php new file mode 100644 index 0000000..8ae49a3 --- /dev/null +++ b/02.iterators.php @@ -0,0 +1,26 @@ +"; +} + + +foreach ($fruits as $fruit) { + echo $fruit . "
"; +} + +$i = 1; +while ($i <= 10) { + echo $i . "
"; + $i++; +} + + +$i2 = 1; +do { + echo $i2 . "
"; + $i2++; +} while ($i2 <= 10); + + +?> \ No newline at end of file diff --git a/03.operators.php b/03.operators.php new file mode 100644 index 0000000..21bd121 --- /dev/null +++ b/03.operators.php @@ -0,0 +1,26 @@ +"; // Outputs 8 +echo $a - $b . "
"; // Outputs 2 +echo $a * $b . "
"; // Outputs 15 +echo $a / $b . "
"; // Outputs 1.6666666666667 +echo $a % $b . "
"; // Outputs 2 + + +echo $a == $b . "
"; // Outputs false +echo $a != $b . "
"; // Outputs true +echo $a < $b . "
"; // Outputs false +echo $a > $b . "
"; + + +$c = true; +$d = false; + +echo ($c && $d) . "
"; // Outputs false +echo ($c || $d) . "
"; // Outputs true +echo !$c . "
"; // Outputs false +echo ($c xor $d) . "
"; // Outputs true +?> \ No newline at end of file diff --git a/04.dates.php b/04.dates.php new file mode 100644 index 0000000..97dc973 --- /dev/null +++ b/04.dates.php @@ -0,0 +1,28 @@ +format("Y-m-d"); + +$date2 = new DateTime("2022-12-20"); +echo $date2->format("Y-m-d"); // Outputs "2022-12-20" + +$timestamp = strtotime("2022-12-20"); +$date3 = new DateTime("@$timestamp"); +echo $date3->format("Y-m-d"); // Outputs "2022-12-20" + +echo date("d"); // Outputs the current day of the month as a 2-digit number (e.g. "01", "02", ..., "31") + +echo $date3->format("d"); // Outputs the current day of the month as a 2-digit number (e.g. "01", "02", ..., "31") + +echo date("m"); // Outputs the current month as a 2-digit number (e.g. "01", "02", ..., "12") + +$date5 = new DateTime(); +echo $date5->format("m"); // Outputs the current month as a 2-digit number (e.g. "01", "02", ..., "12") + +echo date("i"); // Outputs the current minute as a 2-digit number with leading zeros (e.g. "00", "01", ..., "59") + +$date6 = new DateTime(); +echo $date6->format("i"); // Outputs the current minute as a 2-digit number with leading zeros (e.g. "00", "01", ..., "59") + + + +?> \ No newline at end of file diff --git a/05.conditionals.php b/05.conditionals.php new file mode 100644 index 0000000..163d9b9 --- /dev/null +++ b/05.conditionals.php @@ -0,0 +1,83 @@ +format("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday") + +if ($day == "Monday") { + echo "We are on Monday"; +} + + +$month = date("F"); // Get the current month as a full textual representation (e.g. "January", "February", ..., "December") + +if ($month == "October") { + echo "We are in October"; +} else { + echo "We are in $month"; +} + +$date2 = new DateTime(); +$month = $date2->format("F"); // Get the current month as a full textual representation (e.g. "January", "February", ..., "December") + +if ($month == "October") { + echo "We are in October"; +} else { + echo "We are in $month"; +} + +$minute = date("i"); // Get the current minute as a 2-digit number (e.g. "00", "01", ..., "59") + +if ($minute < 10) { + echo "The current minute is less than 10"; +} elseif ($minute > 15) { + echo "The current minute is more than 15"; +} else { + echo "Does not meet any conditions"; +} + +$date3 = new DateTime(); +$minute = $date3->format("i"); // Get the current minute as a 2-digit number (e.g. "00", "01", ..., "59") + +if ($minute < 10) { + echo "The current minute is less than 10"; +} elseif ($minute > 15) { + echo "The current minute is more than 15"; +} else { + echo "Does not meet any conditions"; +} + + +$day = date("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday") + +switch ($day) { + case "Monday": + echo "It's the start of a new week!"; + break; + case "Wednesday": + echo "Hump day!"; + break; + case "Friday": + echo "TGIF!"; + break; + case "Saturday": + echo "Time to relax and enjoy the weekend!"; + break; + case "Sunday": + echo "End of the weekend, time to get ready for another week."; + break; + default: + echo "Just another day..."; + break; +} + + + + + +?> \ No newline at end of file diff --git a/06.types.php b/06.types.php new file mode 100644 index 0000000..d37ced3 --- /dev/null +++ b/06.types.php @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/07.maths.php b/07.maths.php new file mode 100644 index 0000000..dd6af21 --- /dev/null +++ b/07.maths.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/08.strings.php b/08.strings.php new file mode 100644 index 0000000..e7473f0 --- /dev/null +++ b/08.strings.php @@ -0,0 +1,48 @@ + \ No newline at end of file diff --git a/09.arrays.php b/09.arrays.php new file mode 100644 index 0000000..90700a3 --- /dev/null +++ b/09.arrays.php @@ -0,0 +1,32 @@ + apple [1] => banana [2] => orange [3] => 1 [4] => 2.5 [5] => 3 [6] => 4.5 ) + +// Execute the function that once is given an array return the last element of it +echo end($array1); // Outputs "orange" + +// Execute the function that once is given an array add a new element to the array in question +array_push($array1, "mango"); +print_r($array1); // Outputs Array ( [0] => apple [1] => banana [2] => orange [3] => mango ) + + + +?> \ No newline at end of file diff --git a/10.functions.php b/10.functions.php new file mode 100644 index 0000000..543dddc --- /dev/null +++ b/10.functions.php @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/11.phpinfo.php b/11.phpinfo.php new file mode 100644 index 0000000..ba2e1f6 --- /dev/null +++ b/11.phpinfo.php @@ -0,0 +1,5 @@ + \ No newline at end of file