From d7a40884c21f74780948867f8ed69d2cd475251c Mon Sep 17 00:00:00 2001 From: Miquel Date: Mon, 19 Dec 2022 16:50:37 +0100 Subject: [PATCH 01/16] files created --- arrays.php | 0 conditionals.php | 0 dates.php | 0 functions.php | 0 iterators.php | 0 maths.php | 0 operators.php | 0 phpinfo.php | 0 print.php | 0 strings.php | 0 types.php | 0 11 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 arrays.php create mode 100644 conditionals.php create mode 100644 dates.php create mode 100644 functions.php create mode 100644 iterators.php create mode 100644 maths.php create mode 100644 operators.php create mode 100644 phpinfo.php create mode 100644 print.php create mode 100644 strings.php create mode 100644 types.php diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..e69de29 diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..e69de29 diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..e69de29 diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..e69de29 diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..e69de29 diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..e69de29 diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..e69de29 diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..e69de29 diff --git a/print.php b/print.php new file mode 100644 index 0000000..e69de29 diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..e69de29 diff --git a/types.php b/types.php new file mode 100644 index 0000000..e69de29 From 7e3059ade62a9a5d291174f79996c2a638ebd761 Mon Sep 17 00:00:00 2001 From: Miquel Date: Mon, 19 Dec 2022 16:56:58 +0100 Subject: [PATCH 02/16] print file exercise done --- print.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/print.php b/print.php index e69de29..62b8d21 100644 --- a/print.php +++ b/print.php @@ -0,0 +1,8 @@ +'; + +print 'Hello World from print
'; + +$complexValue = ['Value1', 'Value2', ['Value3', 'Value4'], (object) array('index1' => 'Value5') ]; + +print_r($complexValue); From 895d724cc7de7234aeb250ca9daada10fba571c4 Mon Sep 17 00:00:00 2001 From: Miquel Date: Mon, 19 Dec 2022 17:09:29 +0100 Subject: [PATCH 03/16] iterators file exercise done --- iterators.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/iterators.php b/iterators.php index e69de29..f1ef0a9 100644 --- a/iterators.php +++ b/iterators.php @@ -0,0 +1,42 @@ +"; + +for($i = 0 ; $i < 5; $i++){ + echo $i."
"; +} + +$myArray = [1,2,3,4,5]; + +echo "

"; +echo "foreach"; +echo "
"; + +foreach($myArray as $num){ + $num = $num*2; +} + +print_r($myArray); + +echo "

"; +echo "while loop"; +echo "
"; + +$j = 0; + +while($j < 5){ + echo $j; + $j++; +} + +echo "

"; +echo "do while"; +echo "
"; + +$k = 0; + +do{ + echo $k; + $k++; +} while($k < 5) + +?> \ No newline at end of file From 45d49e29e5ad798f613e560f2e69c3a799be0ebb Mon Sep 17 00:00:00 2001 From: Miquel Date: Mon, 19 Dec 2022 17:29:45 +0100 Subject: [PATCH 04/16] operators file exercise done --- operators.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/operators.php b/operators.php index e69de29..7ed5c75 100644 --- a/operators.php +++ b/operators.php @@ -0,0 +1,70 @@ +"; + +var_dump('Hello'); +echo "
"; +var_dump(3); +echo "
"; +var_dump(['Hello', 'World']); +echo "
"; +var_dump((object) array('1' => 'Hello', '2' => 'World')); +echo "
"; +var_dump(false); +echo "
"; +var_dump(2.5); +echo "
"; +var_dump(null); +echo "
"; + +$a = 1; +$b = 2; + +echo "
"; +echo "var_dump() to check arithmetic operators"; +echo "
"; + +var_dump($a + $b == 2); +echo "
"; +var_dump($a - $b == -1); +echo "
"; +var_dump($a * $b == 2); +echo "
"; +var_dump($a / $b == 2); +echo "
"; +var_dump($a % $b == 0); +echo "
"; + +echo "
"; +echo "var_dump() to check comparision operators"; +echo "
"; + +var_dump($a < $b); +echo "
"; +var_dump($a > $b); +echo "
"; +var_dump($a == $b); +echo "
"; +var_dump($a != $b); +echo "
"; +var_dump($a <= $b); +echo "
"; +var_dump($a >= $b); +echo "
"; + +echo "
"; +echo "var_dump() to check logical operators"; +echo "
"; + +var_dump($a < $b && $a == 1); +echo "
"; +var_dump($a > $b || $a == 2); +echo "
"; +var_dump(!($a == $b)); +echo "
"; +var_dump(!($a == 1 xor $b == 2)); +echo "
"; + + +?> \ No newline at end of file From 812dc45bd5ae08483a23651b19668500505bff25 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 08:33:29 +0100 Subject: [PATCH 05/16] dates file exercises done --- conditionals.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ dates.php | 26 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/conditionals.php b/conditionals.php index e69de29..6bdda73 100644 --- a/conditionals.php +++ b/conditionals.php @@ -0,0 +1,53 @@ +'; +} + +if ($month == "October") { + echo "We are in " . $month ."
"; +} else { + echo $month . "
"; +} + +if($minutes < 10){ + echo "the current minute is less than 10
"; +} else if ($minutes > 15){ + echo "the current minute is more than 15
"; +} else{ + echo "does not meet any conditions
"; +} + +switch ($weekDay) { + case 1: + echo "Hey man, today is Monday"; + break; + case 2: + echo "Hey man, today is Tuesday"; + break; + case 3: + echo "Hey man, today is Wednesday"; + break; + case 4: + echo "Hey man, today is Thursday"; + break; + case 5: + echo "Hey man, today is Friday"; + break; + case 6: + echo "Hey man, today is Saturday"; + break; + case 0: + echo "Hey man, today is Sunday"; + break; + + default: + echo "Never getting here..."; + break; +} + diff --git a/dates.php b/dates.php index e69de29..33d54d2 100644 --- a/dates.php +++ b/dates.php @@ -0,0 +1,26 @@ +format('Y-m-m'); + +echo "
"; + +date_default_timezone_set('Europe/Madrid'); + +echo $date->format('m/d/Y'); + +echo "
"; + +echo $date->format('m'); + +echo "
"; + +echo $date->format('i'); + + + + + + +?> \ No newline at end of file From 24ec974376385c262342fdd27ca66cc7465fb257 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 08:35:36 +0100 Subject: [PATCH 06/16] conditionals file exercises done --- conditionals.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/conditionals.php b/conditionals.php index 6bdda73..ebfc8a7 100644 --- a/conditionals.php +++ b/conditionals.php @@ -25,25 +25,25 @@ switch ($weekDay) { case 1: - echo "Hey man, today is Monday"; + echo "Hey man, today is Monday
"; break; case 2: - echo "Hey man, today is Tuesday"; + echo "Hey man, today is Tuesday
"; break; case 3: - echo "Hey man, today is Wednesday"; + echo "Hey man, today is Wednesday
"; break; case 4: - echo "Hey man, today is Thursday"; + echo "Hey man, today is Thursday
"; break; case 5: - echo "Hey man, today is Friday"; + echo "Hey man, today is Friday
"; break; case 6: - echo "Hey man, today is Saturday"; + echo "Hey man, today is Saturday
"; break; case 0: - echo "Hey man, today is Sunday"; + echo "Hey man, today is Sunday
"; break; default: From 0d905671715a06e134753cba3b0c1e20f5a1ead8 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 09:51:22 +0100 Subject: [PATCH 07/16] types file exercises done --- types.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/types.php b/types.php index e69de29..339bbb8 100644 --- a/types.php +++ b/types.php @@ -0,0 +1,15 @@ + "Miquel", 'username' => 'mike', 'age' => 32); + +$nullVariable = null; From 29c2a97c78baa54c8ef23d74ed4488677e8c30b1 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 10:05:33 +0100 Subject: [PATCH 08/16] maths file exercises done --- maths.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/maths.php b/maths.php index e69de29..090cf57 100644 --- a/maths.php +++ b/maths.php @@ -0,0 +1,33 @@ +'; + +function getRoundedValue($num){ + return ceil($num); +} + +echo getRoundedValue(2.34) . '
'; + +function getHighest($arr){ + return max($arr); +} + +echo getHighest([2,5,4,3,6,7,9,2]) . '
'; + +function getLowest($arr){ + return min($arr); +} + +echo getLowest([2,5,4,3,6,7,9,2]) . '
'; + +function getRandom($arr){ + return array_rand($arr); +} + +echo getRandom([2,5,4,3,6,7,9,2]) . '
'; + +?> \ No newline at end of file From b91049364a9d5e4f829c625822742ca72452868a Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 10:36:42 +0100 Subject: [PATCH 09/16] string file exercises done --- strings.php | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/strings.php b/strings.php index e69de29..6fe31db 100644 --- a/strings.php +++ b/strings.php @@ -0,0 +1,66 @@ +'; + +$name = 'Miquel'; + +print $name . "
"; +print $name . " Abella" . "
"; + +function replaceTextInString($textToReplace, $newText, $str) +{ + $newStr = str_replace($textToReplace, $newText, $str); + return $newStr; +} + +echo replaceTextInString('Abella', 'Garcia', 'Miquel Abella') . '
'; + +function replaceTextInStringNotCaseSensitive($textToReplace, $newText, $str) +{ + $newStr = str_ireplace($textToReplace, $newText, $str); + return $newStr; +} + +echo replaceTextInStringNotCaseSensitive('abella', 'garcia', 'Miquel Abella') . '
'; + +function repeatText($text, $times) +{ + return str_repeat($text, $times); +} + +echo repeatText('Miquel', 4) . '
'; + +function getLength($text) +{ + return strlen($text); +} + +echo getLength('Miquel') . '
'; + +function findFirstOcurrencePosition($text, $textToFind) +{ + return strpos($text, $textToFind); +} + +echo findFirstOcurrencePosition('Miquel', 'q') . '
'; + + +function capitalize($text) +{ + return strtoupper($text); +} + +echo capitalize('Miquel') . '
'; + +function convertToLowerCase($text) +{ + return strtolower($text); +} + +echo convertToLowerCase('MIQUEL') . '
'; + +function findValueOfPosition($text, $position) +{ + return substr($text, $position, 1); +} + +echo findValueOfPosition('Miquel', 3) . '
'; From cfa0d95273eb8194ddb7be5fa0e694c21729bcf2 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 10:48:37 +0100 Subject: [PATCH 10/16] arrays file exercises done --- arrays.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/arrays.php b/arrays.php index e69de29..a57728e 100644 --- a/arrays.php +++ b/arrays.php @@ -0,0 +1,38 @@ +'; + +function combineArrays($arr1, $arr2) +{ + return array_merge($arr1, $arr2); +} + +print_r(combineArrays($fruits, $nums)); +echo '
'; + +function returnLast($arr) +{ + return $arr[count($arr) - 1]; +} + +print_r(returnLast($fruits)); +echo '
'; + +function addElement($arr, $elementToAdd) +{ + array_push($arr, $elementToAdd); + return $arr; +} + +print_r(addElement($fruits, 'cherries')); +echo '
'; From ffcbca0520773ebf8f2b83e7795f82a5730143c2 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 10:56:52 +0100 Subject: [PATCH 11/16] functions file exercises done --- functions.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/functions.php b/functions.php index e69de29..3d78ae1 100644 --- a/functions.php +++ b/functions.php @@ -0,0 +1,55 @@ +"; + +function substract($a, $b) +{ + return $a - $b; +} + +echo substract(1, 2) . "
"; + +function multiply($a, $b) +{ + return $a * $b; +} + +echo multiply(1, 2) . "
"; + +function divide($a, $b) +{ + return $a / $b; +} + +echo divide(1, 2) . "
"; + +function calculate($num1, $num2, $operation) +{ + switch ($operation) { + case '+': + echo sum($num1, $num2) . '
'; + break; + case '-': + echo substract($num1, $num2) . '
'; + break; + case '*': + echo multiply($num1, $num2) . '
'; + break; + case '/': + echo divide($num1, $num2) . '
'; + break; + + default: + echo 'This is not a valid operation
'; + break; + } +} + +calculate(2, 3, '+'); +calculate(2, 3, '-'); +calculate(2, 3, '*'); +calculate(2, 3, '/'); From 888bc491f45604e9f5c60fda33f47e473d1f925d Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 10:57:57 +0100 Subject: [PATCH 12/16] called phpinfo() --- phpinfo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpinfo.php b/phpinfo.php index e69de29..01b1150 100644 --- a/phpinfo.php +++ b/phpinfo.php @@ -0,0 +1,3 @@ + Date: Tue, 20 Dec 2022 11:04:11 +0100 Subject: [PATCH 13/16] changed readme --- README.md | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7c787c3..b6c5687 100644 --- a/README.md +++ b/README.md @@ -12,35 +12,20 @@ ## Index -- [Requirements](#requirements) -- [Repository](#repository) +- [How to run](#How-to-run) - [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) - [Resources](#resources) -## Requirements +## How to run -- Learn the basics to program in PHP -- Understand what a server-side language is and what it is used for - -## Repository - -First of all you must fork this project into your GitHub account. - -To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. - -Fork on GitHub +- Install XAMPP +- Run Apache in the Xampp control panel +- The project will run on localhost:80 or http://127.0.0.1/ ## Technologies used \* PHP -## Project delivery - -To deliver this project you must send a Pull Request as explained in the Students Handbook. Remember that the PR title must be with the format -- Solution: + NAME AND SURNAME or TEAM NAMES AND SURNAMES. -- For example: "Solution: Josep Riera", "Solution: Josep Riera, Toni Suárez, Marta Vázquez" - ## Resources - [What can PHP do?](https://www.php.net/manual/es/intro-whatcando.php) From 61bff0b0e256059e77eb3370b7ef4a488a892cf4 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 11:32:15 +0100 Subject: [PATCH 14/16] added comments to files --- arrays.php | 11 +++++++++++ conditionals.php | 11 +++++++++++ dates.php | 4 ++++ functions.php | 3 +++ iterators.php | 3 +++ maths.php | 10 ++++++++++ phpinfo.php | 1 + print.php | 3 +++ strings.php | 13 +++++++++++++ types.php | 2 ++ 10 files changed, 61 insertions(+) diff --git a/arrays.php b/arrays.php index a57728e..4e09f0e 100644 --- a/arrays.php +++ b/arrays.php @@ -1,10 +1,15 @@ '; +// combine arrays + function combineArrays($arr1, $arr2) { return array_merge($arr1, $arr2); @@ -20,6 +27,8 @@ function combineArrays($arr1, $arr2) print_r(combineArrays($fruits, $nums)); echo '
'; +// return last element + function returnLast($arr) { return $arr[count($arr) - 1]; @@ -28,6 +37,8 @@ function returnLast($arr) print_r(returnLast($fruits)); echo '
'; +// add element to array + function addElement($arr, $elementToAdd) { array_push($arr, $elementToAdd); diff --git a/conditionals.php b/conditionals.php index ebfc8a7..981b0ef 100644 --- a/conditionals.php +++ b/conditionals.php @@ -1,20 +1,29 @@ '; } +// check if month is october + if ($month == "October") { echo "We are in " . $month ."
"; } else { echo $month . "
"; } +//check minutes + if($minutes < 10){ echo "the current minute is less than 10
"; } else if ($minutes > 15){ @@ -23,6 +32,8 @@ echo "does not meet any conditions
"; } +//display different message depending on what day today is + switch ($weekDay) { case 1: echo "Hey man, today is Monday
"; diff --git a/dates.php b/dates.php index 33d54d2..ec67535 100644 --- a/dates.php +++ b/dates.php @@ -1,7 +1,11 @@ format('Y-m-m'); echo "
"; diff --git a/functions.php b/functions.php index 3d78ae1..6c1c61d 100644 --- a/functions.php +++ b/functions.php @@ -1,4 +1,7 @@ "; for($i = 0 ; $i < 5; $i++){ diff --git a/maths.php b/maths.php index 090cf57..c80b528 100644 --- a/maths.php +++ b/maths.php @@ -1,5 +1,7 @@ '; +//get highest value of array of numbers + function getHighest($arr){ return max($arr); } echo getHighest([2,5,4,3,6,7,9,2]) . '
'; +//get lowest value of array of numbers + function getLowest($arr){ return min($arr); } echo getLowest([2,5,4,3,6,7,9,2]) . '
'; +//get random value from array + function getRandom($arr){ return array_rand($arr); } diff --git a/phpinfo.php b/phpinfo.php index 01b1150..7e8b997 100644 --- a/phpinfo.php +++ b/phpinfo.php @@ -1,3 +1,4 @@ '; print 'Hello World from print
'; diff --git a/strings.php b/strings.php index 6fe31db..9fe6944 100644 --- a/strings.php +++ b/strings.php @@ -6,6 +6,8 @@ print $name . "
"; print $name . " Abella" . "
"; +// replace text of string + function replaceTextInString($textToReplace, $newText, $str) { $newStr = str_replace($textToReplace, $newText, $str); @@ -22,6 +24,8 @@ function replaceTextInStringNotCaseSensitive($textToReplace, $newText, $str) echo replaceTextInStringNotCaseSensitive('abella', 'garcia', 'Miquel Abella') . '
'; +// repeat n times a string + function repeatText($text, $times) { return str_repeat($text, $times); @@ -29,6 +33,8 @@ function repeatText($text, $times) echo repeatText('Miquel', 4) . '
'; +// get length of a string + function getLength($text) { return strlen($text); @@ -36,6 +42,8 @@ function getLength($text) echo getLength('Miquel') . '
'; +// find first occurrence of string + function findFirstOcurrencePosition($text, $textToFind) { return strpos($text, $textToFind); @@ -43,6 +51,7 @@ function findFirstOcurrencePosition($text, $textToFind) echo findFirstOcurrencePosition('Miquel', 'q') . '
'; +// capitalize all string function capitalize($text) { @@ -51,6 +60,8 @@ function capitalize($text) echo capitalize('Miquel') . '
'; +// lowercase string + function convertToLowerCase($text) { return strtolower($text); @@ -58,6 +69,8 @@ function convertToLowerCase($text) echo convertToLowerCase('MIQUEL') . '
'; +// find value of a string given the position + function findValueOfPosition($text, $position) { return substr($text, $position, 1); diff --git a/types.php b/types.php index 339bbb8..aea05c6 100644 --- a/types.php +++ b/types.php @@ -1,5 +1,7 @@ Date: Tue, 20 Dec 2022 11:36:04 +0100 Subject: [PATCH 15/16] moved phpinfo file into folder and renamed file to index.php --- phpinfo.php => phpinfo/index.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpinfo.php => phpinfo/index.php (100%) diff --git a/phpinfo.php b/phpinfo/index.php similarity index 100% rename from phpinfo.php rename to phpinfo/index.php From 97a7736e37fc602dd092313237d0aa091913d665 Mon Sep 17 00:00:00 2001 From: Miquel Date: Tue, 20 Dec 2022 12:32:26 +0100 Subject: [PATCH 16/16] made it beautiful? --- arrays.php | 57 ++++++++++++++++++++++++++++++- conditionals.php | 67 ++++++++++++++++++++++++++++++++++-- dates.php | 19 ++++++++++- functions.php | 61 ++++++++++++++++++++++++++++++++- iterators.php | 49 +++++++++++++++++++++++++-- maths.php | 51 ++++++++++++++++++++++++++-- operators.php | 74 ++++++++++++++++++++++++++++++++++++++++ print.php | 14 ++++++++ strings.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ types.php | 21 +++++++++++- 10 files changed, 491 insertions(+), 10 deletions(-) diff --git a/arrays.php b/arrays.php index 4e09f0e..4cbba0a 100644 --- a/arrays.php +++ b/arrays.php @@ -1,5 +1,5 @@ results

'; // array declarations $fruits = ['orange', 'banana', 'apple']; @@ -47,3 +47,58 @@ function addElement($arr, $elementToAdd) print_r(addElement($fruits, 'cherries')); echo '
'; + + + +echo '

Arrays

+
+// array declarations
+
+$fruits = ["orange", "banana", "apple"];
+
+$nums = [1, 2.4, 5, 3, 4.6];
+
+$multidimensionArr = ["hello", "world", [1, 2, 3]];
+
+// get length of array
+
+function getLengthOfArray($arr)
+{
+    return count($arr);
+}
+
+echo getLengthOfArray($multidimensionArr) . "
"; + +// combine arrays + +function combineArrays($arr1, $arr2) +{ + return array_merge($arr1, $arr2); +} + +print_r(combineArrays($fruits, $nums)); +echo "
"; + +// return last element + +function returnLast($arr) +{ + return $arr[count($arr) - 1]; +} + +print_r(returnLast($fruits)); +echo "
"; + +// add element to array + +function addElement($arr, $elementToAdd) +{ + array_push($arr, $elementToAdd); + return $arr; +} + +print_r(addElement($fruits, "cherries")); +echo "
"; + +
+'; \ No newline at end of file diff --git a/conditionals.php b/conditionals.php index 981b0ef..1c76f5d 100644 --- a/conditionals.php +++ b/conditionals.php @@ -1,7 +1,6 @@ results

'; // set default timezone - date_default_timezone_set('Europe/Madrid'); $weekDay = date('w'); @@ -62,3 +61,67 @@ break; } + +echo ' +

Conditionals

+

+date_default_timezone_set("Europe/Madrid");
+
+$weekDay = date("w");
+$month = date("F");
+$minutes = date("i");
+
+// check if today is monday
+
+if ($weekDay == 1) {
+ echo "Today is Monday
";
+}
+
+// check if month is october
+
+if ($month == "October") {
+ echo "We are in " . $month ."
";
+} else {
+ echo $month . "
";
+}
+
+//check minutes
+
+if($minutes < 10){
+ echo "the current minute is less than 10
";
+} else if ($minutes > 15){
+ echo "the current minute is more than 15
";
+} else{
+ echo "does not meet any conditions
";
+}
+' . '
+//display different message depending on what day today is
+
+switch ($weekDay) {
+ case 1:
+ echo "Hey man, today is Monday
";
+ break;
+ case 2:
+ echo "Hey man, today is Tuesday
";
+ break;
+ case 3:
+ echo "Hey man, today is Wednesday
";
+ break;
+ case 4:
+ echo "Hey man, today is Thursday
";
+ break;
+ case 5:
+ echo "Hey man, today is Friday
";
+ break;
+ case 6:
+ echo "Hey man, today is Saturday
";
+ break;
+ case 0:
+ echo "Hey man, today is Sunday
";
+ break;
+
+ default:
+ echo "Never getting here...";
+ break;
+ }
'; +?> \ No newline at end of file diff --git a/dates.php b/dates.php index ec67535..b382333 100644 --- a/dates.php +++ b/dates.php @@ -1,5 +1,5 @@ results

'; // instance DateTime $date = new DateTime(); @@ -22,9 +22,26 @@ echo $date->format('i'); +echo '
+$date = new DateTime();
+
+// different time formats
+
+echo $date->format("Y-m-m");
 
+echo "
"; +date_default_timezone_set("Europe/Madrid"); +echo $date->format("m/d/Y"); + +echo "
"; + +echo $date->format("m"); + +echo "
"; +echo $date->format("i"); +
' ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 6c1c61d..1e80c60 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,5 @@ results

'; // functions to calculate values function sum($a, $b) @@ -56,3 +56,62 @@ function calculate($num1, $num2, $operation) calculate(2, 3, '-'); calculate(2, 3, '*'); calculate(2, 3, '/'); + +echo '
+
+function sum($a, $b)
+{
+    return $a + $b;
+}
+
+echo sum(1, 2) . "
"; + +function substract($a, $b) +{ + return $a - $b; +} + +echo substract(1, 2) . "
"; + +function multiply($a, $b) +{ + return $a * $b; +} + +echo multiply(1, 2) . "
"; + +function divide($a, $b) +{ + return $a / $b; +} + +echo divide(1, 2) . "
"; + +function calculate($num1, $num2, $operation) +{ + switch ($operation) { + case "+": + echo sum($num1, $num2) . "
"; + break; + case "-": + echo substract($num1, $num2) . "
"; + break; + case "*": + echo multiply($num1, $num2) . "
"; + break; + case "/": + echo divide($num1, $num2) . "
"; + break; + + default: + echo "This is not a valid operation
"; + break; + } +} + +calculate(2, 3, "+"); +calculate(2, 3, "-"); +calculate(2, 3, "*"); +calculate(2, 3, "/"); + +
'; \ No newline at end of file diff --git a/iterators.php b/iterators.php index 56498fc..d79069d 100644 --- a/iterators.php +++ b/iterators.php @@ -1,5 +1,5 @@ results

'; // different iterators echo "for loop
"; @@ -40,6 +40,51 @@ do{ echo $k; $k++; -} while($k < 5) +} while($k < 5); + +echo ' +

Iterators

+
+
+echo "for loop 
"; + +for($i = 0 ; $i < 5; $i++){ + echo $i."
"; +} + +$myArray = [1,2,3,4,5]; + +echo "

"; +echo "foreach"; +echo "
"; + +foreach($myArray as $num){ + $num = $num*2; +} + +print_r($myArray); +echo "

"; +echo "while loop"; +echo "
"; + +$j = 0; + +while($j < 5){ + echo $j; + $j++; +} + +echo "

"; +echo "do while"; +echo "
"; + +$k = 0; + +do{ + echo $k; + $k++; +} while($k < 5) +
+' ?> \ No newline at end of file diff --git a/maths.php b/maths.php index c80b528..2129de6 100644 --- a/maths.php +++ b/maths.php @@ -1,5 +1,5 @@ results

'; // get absolute function getAbsoluteValue($num){ @@ -40,4 +40,51 @@ function getRandom($arr){ echo getRandom([2,5,4,3,6,7,9,2]) . '
'; -?> \ No newline at end of file +echo ' +

Maths


+
+function getAbsoluteValue($num){
+    return abs($num);
+}
+
+echo getAbsoluteValue(-5) . "
"; + +function getRoundedValue($num){ + return ceil($num); +} + +// get rounded to next integer + +echo getRoundedValue(2.34) . "
"; + +//get highest value of array of numbers + +function getHighest($arr){ + return max($arr); +} + +echo getHighest([2,5,4,3,6,7,9,2]) . "
"; + +//get lowest value of array of numbers + +function getLowest($arr){ + return min($arr); +} + +echo getLowest([2,5,4,3,6,7,9,2]) . "
"; + +//get random value from array + +function getRandom($arr){ + return array_rand($arr); +} + +echo getRandom([2,5,4,3,6,7,9,2]) . "
"; +
+' + + + + + +?> diff --git a/operators.php b/operators.php index 7ed5c75..a1639db 100644 --- a/operators.php +++ b/operators.php @@ -1,4 +1,5 @@ results

'; echo "var_dump() to check value type and value"; echo "
"; @@ -66,5 +67,78 @@ var_dump(!($a == 1 xor $b == 2)); echo "
"; +echo '

Operators

+
+
+echo "var_dump() to check value type and value";
+echo "
"; + +var_dump("Hello"); +echo "
"; +var_dump(3); +echo "
"; +var_dump(["Hello", "World"]); +echo "
"; +var_dump((object) array("1" => "Hello", "2" => "World")); +echo "
"; +var_dump(false); +echo "
"; +var_dump(2.5); +echo "
"; +var_dump(null); +echo "
"; + +$a = 1; +$b = 2; + +echo "
"; +echo "var_dump() to check arithmetic operators"; +echo "
"; + +var_dump($a + $b == 2); +echo "
"; +var_dump($a - $b == -1); +echo "
"; +var_dump($a * $b == 2); +echo "
"; +var_dump($a / $b == 2); +echo "
"; +var_dump($a % $b == 0); +echo "
"; + +echo "
"; +echo "var_dump() to check comparision operators"; +echo "
"; + +var_dump($a < $b); +echo "
"; +var_dump($a > $b); +echo "
"; +var_dump($a == $b); +echo "
"; +var_dump($a != $b); +echo "
"; +var_dump($a <= $b); +echo "
"; +var_dump($a >= $b); +echo "
"; + +echo "
"; +echo "var_dump() to check logical operators"; +echo "
"; + +var_dump($a < $b && $a == 1); +echo "
"; +var_dump($a > $b || $a == 2); +echo "
"; +var_dump(!($a == $b)); +echo "
"; +var_dump(!($a == 1 xor $b == 2)); +echo "
"; + + +
+ +' ?> \ No newline at end of file diff --git a/print.php b/print.php index 513d843..bf1fbde 100644 --- a/print.php +++ b/print.php @@ -9,3 +9,17 @@ $complexValue = ['Value1', 'Value2', ['Value3', 'Value4'], (object) array('index1' => 'Value5') ]; print_r($complexValue); + +echo '

Print

+
+
+echo "Hello World from echo 
"; + +print "Hello World from print
"; + +$complexValue = ["Value1", "Value2", ["Value3", "Value4"], (object) array("index1" => "Value5") ]; + +print_r($complexValue); +
+ +'; \ No newline at end of file diff --git a/strings.php b/strings.php index 9fe6944..ecdab43 100644 --- a/strings.php +++ b/strings.php @@ -1,4 +1,6 @@ results

'; + print 'Hello world
'; $name = 'Miquel'; @@ -77,3 +79,89 @@ function findValueOfPosition($text, $position) } echo findValueOfPosition('Miquel', 3) . '
'; + +echo '

Strings

+
+print "Hello world 
"; + +$name = "Miquel"; + +print $name . "
"; +print $name . " Abella" . "
"; + +// replace text of string + +function replaceTextInString($textToReplace, $newText, $str) +{ + $newStr = str_replace($textToReplace, $newText, $str); + return $newStr; +} + +echo replaceTextInString("Abella", "Garcia", "Miquel Abella") . "
"; + +function replaceTextInStringNotCaseSensitive($textToReplace, $newText, $str) +{ + $newStr = str_ireplace($textToReplace, $newText, $str); + return $newStr; +} + +echo replaceTextInStringNotCaseSensitive("abella", "garcia", "Miquel Abella") . "
"; + +// repeat n times a string + +function repeatText($text, $times) +{ + return str_repeat($text, $times); +} + +echo repeatText("Miquel", 4) . "
"; + +// get length of a string + +function getLength($text) +{ + return strlen($text); +} + +echo getLength("Miquel") . "
"; + +// find first occurrence of string + +function findFirstOcurrencePosition($text, $textToFind) +{ + return strpos($text, $textToFind); +} + +echo findFirstOcurrencePosition("Miquel", "q") . "
"; + +// capitalize all string + +function capitalize($text) +{ + return strtoupper($text); +} + +echo capitalize("Miquel") . "
"; + +// lowercase string + +function convertToLowerCase($text) +{ + return strtolower($text); +} + +echo convertToLowerCase("MIQUEL") . "
"; + +// find value of a string given the position + +function findValueOfPosition($text, $position) +{ + return substr($text, $position, 1); +} + +echo findValueOfPosition("Miquel", 3) . "
"; +
+ + + +'; \ No newline at end of file diff --git a/types.php b/types.php index aea05c6..d18990e 100644 --- a/types.php +++ b/types.php @@ -1,5 +1,5 @@ results

'; // value types $isTrue = false; @@ -15,3 +15,22 @@ $user = (object) array('name' => "Miquel", 'username' => 'mike', 'age' => 32); $nullVariable = null; + +echo '

Types

+
+$isTrue = false;
+
+$number = 5;
+
+$floatNumber = 2.5;
+
+$name = "Miquel";
+
+$fruits = ["apple", "banana", "orange"];
+
+$user = (object) array("name" => "Miquel", "username" => "mike", "age" => 32);
+
+$nullVariable = null;
+
+ +';