diff --git a/README.md b/README.md index 7c787c3..556784b 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,32 @@ -`#php` `#basics` `#master-in-software-development` +`#php` `#basics` `#master-in-software-development` -# PHP Basics - -
-
-
+
## 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
+\* PHP
-- [What can PHP do?](https://www.php.net/manual/es/intro-whatcando.php)
-- [Sample guide for README](https://gist.github.com/Villanuevand/6386899f70346d4580c723232524d35a)
-- [XAMPP](https://www.apachefriends.org/es/index.html)
-- [How to install XAMPP on Windows](https://www.youtube.com/watch?v=h6DEDm7C37A)
-- [What is a web server?](https://www.youtube.com/watch?v=Yt1nesKi5Ec)
-- [Web server basics](https://www.youtube.com/watch?v=3VqfpVKvlxQ)
+## Autor
+* **[David Moina](https://github.com/davidmoina)**
\ No newline at end of file
diff --git a/arrays.php b/arrays.php
new file mode 100644
index 0000000..7789d57
--- /dev/null
+++ b/arrays.php
@@ -0,0 +1,31 @@
+Arrays";
+
+ $arr1 = array("tomato", "potato", "carrot");
+
+ echo "First array: ", var_dump($arr1),"
"; + + $arr2 = array(10, 2.5 , 7, 200, 3.2); + + echo "Second array: ", var_dump($arr2),"
"; + + #multidimensional array + $arrMult = array("user" => array("david", "moina"), "occupation" => array("student", "employee")); + + echo "Multidimensional array: ", var_dump($arrMult),"
"; + + #length of an array + echo "Length of second array is ", count($arr2),"
"; + + #array combination + $arrComb = array_merge($arr1, $arr2); + echo "The combination of the first and second array is", var_dump($arrComb), "
"; + + #last element of an array + echo "The last element of the first array is: ", end($arr1),"
"; + + # add a new element to the array + array_push($arr1, "banana"); + + echo "Now I added banana to the first array and it is the result: ", var_dump($arr1),"
"; +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..3fa3a27 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,55 @@ +Conditionals"; + + #condition that evaluates whether the current day is Monday + $day = date("l"); + + if($day == "Monday") { + echo "We are on Monday"; + } + + #condition that evaluates whether the current month is October + $month = date("F"); + + if($month == "October") { + echo "We are in Octoberthe current minute is less than 10
"; + } elseif ($minute > 15) { + echo "the current minute is more than 15
"; + } else { + echo "does not meet any conditions
"; + } + + #switch conditional + switch($day) { + case "Monday": + echo "Today is $day
"; + break; + case "Tuesday": + echo "Today is $day
"; + break; + case "Wednesday": + echo "Today is $day
"; + break; + case "Thursday": + echo "Today is $day
"; + break; + case "Friday": + echo "Today is $day
"; + break; + case "Saturday": + echo "Today is $day
"; + break; + case "Sunday": + echo "Today is $day
"; + break; + } +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..d79562b --- /dev/null +++ b/dates.php @@ -0,0 +1,21 @@ +Dates"; + + $dateVar = new DateTime(); + + #date with format method + echo $dateVar-> format("Y-m-d"), "The result of 2 + 5 = ", sum(2, 5),"
"; + + #function to multiply two numbers + function mul($num1, $num2) { + return $num1 * $num2; + } + + echo "The result of 2 x 5 = ", mul(2, 5),"
"; + + #function to divide two numbers + function div($num1, $num2) { + return $num1 / $num2; + } + + echo "The result of 10 / 2 = ", div(10, 2),"
"; + + #function + function operations($num1, $num2, $type) { + if($type == "add" || $type == "+") { + echo "$num1 + $num2 = ",sum($num1, $num2); + } elseif($type == "multiply" || $type == "*" || $type == "x") { + echo "$num1 x $num2 = ",mul($num1, $num2); + } elseif($type == "divide" || $type == "/") { + echo "$num1 / $num2 = ",div($num1, $num2); + } else { + echo "Please enter a valid operation"; + } + } + + operations(8, 2, "/"); +?> \ No newline at end of file diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..43c24be --- /dev/null +++ b/iterators.php @@ -0,0 +1,34 @@ +Iterators"; + + for($i = 0; $i < 10; $i++) { + print $i; + } + + print "The absolute value of -5 is $absValue
"; + + #rounded value + $roundedValue = ceil(2.5); + echo "The rounded value to the next highest integer of 2.5 is $roundedValue
"; + + $maxValue = max(3, 4, 9, 1, 7); + echo "The maximum value of (3, 4, 9, 1, 7) is $maxValue
"; + + $minValue = min(3, 4, 9, 1, 7); + echo "The minimum value of (3, 4, 9, 1, 7) is $minValue
"; + + $randNum = rand(); + + echo "A random number: $randNum"; +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..82d34cf --- /dev/null +++ b/operators.php @@ -0,0 +1,49 @@ +Operators"; + + #arithmetic operators + print "Hello Assembler
"; + + $name = "David"; + + echo $name; + + echo "My name is $name.
"; + + # replace text in a string + $phrase = "University is great to study in it.
"; + + echo str_replace("University", "Assembler", $phrase); + + $other_phrase = "I like play Football
"; + + echo str_ireplace("football", "video games", $other_phrase); + + #function that allows you to write a text N times + $txt = "PHP "; + + echo str_repeat($txt, 5); + + #length of a string + echo "Length of $name: ", strlen($name), "
"; + + #obtain the position of the first occurrence of a text within a text string + echo "Position of v in $name: ", strpos($name, "v"),"
"; + + #converts a string to uppercase + echo "My name converted to uppercase: ", strtoupper($name),"
"; + + #converts a string to lowercase + echo "My name converted to lowercase: ", strtolower($name),"
"; + + #obtain a text substring from a given position + echo "A substring text of $name from a given position(2): ", substr($name, 2),"
" +?> \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..5ac9fec --- /dev/null +++ b/types.php @@ -0,0 +1,22 @@ +this is a boolean: $boolean"; + + $integer = 10; + echo "this is a integer: $integer
"; + + $float = 2.5; + echo "this is a float: $float
"; + + $string = "Hello"; + echo "this is a string: $string
"; + + $arr = array(1, 2, 3 , 4); + echo "this is an array: ", var_dump($arr), "
"; + + $obj = (object)["el_1" => "item1", "el_2" => "item2"]; + echo "this is an object: ", var_dump($obj), "
"; + + $nll = NULL; + echo "this is a NULL type: $nll
" +?> \ No newline at end of file