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.
-
-
+- 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)
diff --git a/arrays.php b/arrays.php
new file mode 100644
index 0000000..4cbba0a
--- /dev/null
+++ b/arrays.php
@@ -0,0 +1,104 @@
+results
';
+// 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 '
';
+
+
+
+echo '
+// 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) . "+'; \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..1c76f5d --- /dev/null +++ b/conditionals.php @@ -0,0 +1,127 @@ +results
"; + +// 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/dates.php b/dates.php new file mode 100644 index 0000000..b382333 --- /dev/null +++ b/dates.php @@ -0,0 +1,47 @@ +results
+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;
+ }
+$date = new DateTime(); + +// different time formats + +echo $date->format("Y-m-m"); + +echo "' + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..1e80c60 --- /dev/null +++ b/functions.php @@ -0,0 +1,117 @@ +results
"; + +date_default_timezone_set("Europe/Madrid"); + +echo $date->format("m/d/Y"); + +echo "
"; + +echo $date->format("m"); + +echo "
"; + +echo $date->format("i"); +
+ +function sum($a, $b) +{ + return $a + $b; +} + +echo sum(1, 2) . "'; \ No newline at end of file diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..d79069d --- /dev/null +++ b/iterators.php @@ -0,0 +1,90 @@ +results
"; + +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, "/"); + +
+ +echo "for loop+' +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..2129de6 --- /dev/null +++ b/maths.php @@ -0,0 +1,90 @@ +results
"; + +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) +
+function getAbsoluteValue($num){ + return abs($num); +} + +echo getAbsoluteValue(-5) . "+' + + + + + +?> diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..a1639db --- /dev/null +++ b/operators.php @@ -0,0 +1,144 @@ +results
"; + +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]) . "
"; +
+ +echo "var_dump() to check value type and value"; +echo "+ +' + +?> \ No newline at end of file diff --git a/phpinfo/index.php b/phpinfo/index.php new file mode 100644 index 0000000..7e8b997 --- /dev/null +++ b/phpinfo/index.php @@ -0,0 +1,4 @@ +'; + +print 'Hello World from print
"; + +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 "
"; + + +
+ +echo "Hello World from echo+ +'; \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..ecdab43 --- /dev/null +++ b/strings.php @@ -0,0 +1,167 @@ +results
"; + +print "Hello World from print
"; + +$complexValue = ["Value1", "Value2", ["Value3", "Value4"], (object) array("index1" => "Value5") ]; + +print_r($complexValue); +
+print "Hello world+ + + +'; \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..d18990e --- /dev/null +++ b/types.php @@ -0,0 +1,36 @@ +results
"; + +$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) . "
"; +
+$isTrue = false; + +$number = 5; + +$floatNumber = 2.5; + +$name = "Miquel"; + +$fruits = ["apple", "banana", "orange"]; + +$user = (object) array("name" => "Miquel", "username" => "mike", "age" => 32); + +$nullVariable = null; ++ +';