From 90d4789e5b73c5152e62ba4f32b70f6c1d6fa4ab Mon Sep 17 00:00:00 2001 From: Marian Roibu Date: Tue, 20 Dec 2022 10:33:02 +0100 Subject: [PATCH 1/2] number 1, print --- 01.print.php | 11 +++++++ 02.iterators.php | 26 +++++++++++++++ 03.operators.php | 26 +++++++++++++++ 04.dates.php | 28 ++++++++++++++++ 05.conditionals.php | 80 +++++++++++++++++++++++++++++++++++++++++++++ 06.types.php | 0 07.maths.php | 20 ++++++++++++ 08.strings.php | 48 +++++++++++++++++++++++++++ 09.arrays.php | 32 ++++++++++++++++++ 10.functions.php | 38 +++++++++++++++++++++ 11.phpinfo.php | 0 11 files changed, 309 insertions(+) create mode 100644 01.print.php create mode 100644 02.iterators.php create mode 100644 03.operators.php create mode 100644 04.dates.php create mode 100644 05.conditionals.php create mode 100644 06.types.php create mode 100644 07.maths.php create mode 100644 08.strings.php create mode 100644 09.arrays.php create mode 100644 10.functions.php create mode 100644 11.phpinfo.php 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..203650f --- /dev/null +++ b/02.iterators.php @@ -0,0 +1,26 @@ +"; +} + + +foreach ($fruits as $fruit) { + echo $fruit . "
"; +} + +$i = 1; +while ($i <= 10) { + echo $i . "
"; + $i++; +} +echo"que pasa?" + +$i = 1; +do { + echo $i . "
"; + $i++; +} while ($i <= 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..846cd6a --- /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 $date4->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..6e19f51 --- /dev/null +++ b/05.conditionals.php @@ -0,0 +1,80 @@ +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..e69de29 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..e69de29 From 22b464cfd18ea0afbe95cef3af3e0af5b2ab429d Mon Sep 17 00:00:00 2001 From: Marian Roibu Date: Wed, 21 Dec 2022 09:39:16 +0100 Subject: [PATCH 2/2] fixed errors --- 02.iterators.php | 10 +++++----- 04.dates.php | 2 +- 05.conditionals.php | 5 ++++- 06.types.php | 28 ++++++++++++++++++++++++++++ 11.phpinfo.php | 5 +++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/02.iterators.php b/02.iterators.php index 203650f..8ae49a3 100644 --- a/02.iterators.php +++ b/02.iterators.php @@ -14,13 +14,13 @@ echo $i . "
"; $i++; } -echo"que pasa?" -$i = 1; + +$i2 = 1; do { - echo $i . "
"; - $i++; -} while ($i <= 10); + echo $i2 . "
"; + $i2++; +} while ($i2 <= 10); ?> \ No newline at end of file diff --git a/04.dates.php b/04.dates.php index 846cd6a..97dc973 100644 --- a/04.dates.php +++ b/04.dates.php @@ -11,7 +11,7 @@ echo date("d"); // Outputs the current day of the month as a 2-digit number (e.g. "01", "02", ..., "31") -echo $date4->format("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") diff --git a/05.conditionals.php b/05.conditionals.php index 6e19f51..163d9b9 100644 --- a/05.conditionals.php +++ b/05.conditionals.php @@ -7,7 +7,7 @@ } $date1 = new DateTime(); -$day = $date->format("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday") +$day = $date1->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"; @@ -77,4 +77,7 @@ } + + + ?> \ No newline at end of file diff --git a/06.types.php b/06.types.php index e69de29..d37ced3 100644 --- a/06.types.php +++ b/06.types.php @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/11.phpinfo.php b/11.phpinfo.php index e69de29..ba2e1f6 100644 --- a/11.phpinfo.php +++ b/11.phpinfo.php @@ -0,0 +1,5 @@ + \ No newline at end of file