From 41e867344fc921b359ed7d0f726a9d3fae441124 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez Date: Tue, 20 Dec 2022 21:31:29 +0100 Subject: [PATCH 1/4] first commit --- conditionals.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++ dates.php | 30 ++++++++++++++++++++ iterators.php | 32 +++++++++++++++++++++ operators.php | 50 +++++++++++++++++++++++++++++++++ phpinfo/index.php | 3 ++ print.php | 11 ++++++++ types.php | 22 +++++++++++++++ 7 files changed, 219 insertions(+) create mode 100644 conditionals.php create mode 100644 dates.php create mode 100644 iterators.php create mode 100644 operators.php create mode 100644 phpinfo/index.php create mode 100644 print.php create mode 100644 types.php diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..a51ff5d --- /dev/null +++ b/conditionals.php @@ -0,0 +1,71 @@ +Are we on Monday?"; + +if (date("w") == 1) { + echo "Today is Monday
"; +} else{ + echo "today isn´t Monday"; +} +echo "

"; + +echo "

conditional to check if the current month is October

"; + +if (date("F") == "October") { + echo "We are in October"; +} else { + echo date("F"); +} +echo "

"; + +echo "

doble condicional about current minute

"; + + +if(date("i") < 10 ) { + echo "the current minute is less than 10"; +} else if (date("i") > 15) { + echo "the current minute is more than 15"; +} else { + echo "does not meet any conditions"; +} + +echo "

"; +//podrias crear una variable para los dates (date("i"), date("F") y date("w")) rollo $min, $month y $day + +echo "

Daily message with switch

"; + +$day = date("w"); + +switch($day) { + case $day == 1: + echo "Today is Monday :("; + break; + + case $day == 2: + echo "today is Tuesday :("; + break; + + case $day == 3: + echo "today is Wednesday :|"; + break; + + case $day == 4: + echo "today is Thursday :|"; + break; + + case $day == 5: + echo "today is Friday :)"; + break; + + case $day == 6: + echo "today is Saturday :D"; + break; + + case $day == 0: + echo "today is Sunday :)"; + break; +} + + + +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..4d3f364 --- /dev/null +++ b/dates.php @@ -0,0 +1,30 @@ +Instance the DateTime!"; + +echo '
$date = new DateTime()
'; +$date = new DateTime(); +echo "
"; + +echo "

get the current day in any format"; +echo "
"; + +echo $date->format('d-m-Y'); + +echo "

get the current day"; +echo "
"; + +echo $date->format('Y-m-d'); + +echo "

Get the current month in numerical format (1-12)"; +echo "
"; + +echo $date->format('m'); + +echo "

Get the current minute with leading zeros (00 - 59)"; +echo "
"; + +echo $date->format('i'); + + +?> diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..d6eb38b --- /dev/null +++ b/iterators.php @@ -0,0 +1,32 @@ +for loop

"; +for ($i = 0; $i <= 8; $i++){ + echo $i; +} + +echo "

for each

"; +$array = ["bread","milk","onions","eggs"]; +foreach ($array as $valor) { + print "$valor"; +} + +echo "

While

"; + +$num = 1; + +while($num <= 5) { + echo $num; + $num++; +} + +echo "

Do while

"; + +$numero = 1; + +do{ + echo $numero; + $numero++; +} +while($numero < 6); + +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..eb550e3 --- /dev/null +++ b/operators.php @@ -0,0 +1,50 @@ +arithmetic operators"; +echo '
+var_dump(12 + 12 == 24);
+var_dump(12 - 12 == 24);
+var_dump(12 * 12 == 144);
+var_dump(12 / 12 == 12);
+var_dump(12 % 12 == 24);
+
'; +var_dump(12 + 12 == 24); +echo "
"; +var_dump(12 - 12 == 24); +echo "
"; +var_dump(12 * 12 == 144); +echo "
"; +var_dump(12 / 12 == 12); +echo "
"; +var_dump(12 % 12 == 24); + +echo "

comparison operators

"; + +echo '
+var_dump(3==4);
+var_dump(3!=4);
+var_dump(3<4);
+var_dump(3>4);
+var_dump(3<=4);
+var_dump(3>=4);
+
'; + +var_dump(3==4); +echo "
"; +var_dump(3!=4); +echo "
"; +var_dump(3<4); +echo "
"; +var_dump(3>4); +echo "
"; +var_dump(3<=4); +echo "
"; +var_dump(3>=4); + +echo "

Logical operators

"; + +var_dump(2 < 3 && 4 > 8); +var_dump(2 > 3 || 7 > 1); +var_dump(2 < 3 xor 4 > 8); #devuelve true solo si uno es true y el otro no lo es +var_dump(! 2!=3); # devuelve true si X no es true + +?> \ No newline at end of file diff --git a/phpinfo/index.php b/phpinfo/index.php new file mode 100644 index 0000000..e2b4c37 --- /dev/null +++ b/phpinfo/index.php @@ -0,0 +1,3 @@ + diff --git a/print.php b/print.php new file mode 100644 index 0000000..f9bd144 --- /dev/null +++ b/print.php @@ -0,0 +1,11 @@ +Instruction with echo"; +echo 'bread',",",' milk',",",' onions...'; + +echo "

Instruction with print

"; +print "bread, milk, onions..."; + +echo "

Instruction with print_r

"; +$shoppingList = array("bread","milk","onions","eggs"); + print_r($shoppingList); +?> \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..2949a5c --- /dev/null +++ b/types.php @@ -0,0 +1,22 @@ +Types of variables and data"; +echo "boolean, integer, float, string, array, object, null"; +echo "
"; + +echo '
+$bool = false;
+
+$integer = 17;
+
+$floatNum = 3.4;
+
+$pet = "dog";
+
+$animals = ["wolf", "monkey", "cat", "parrot"];
+
+$animal = (object) array("specie" => "dog", "name" => "Roberto", "age" => 5, "nature" => "docile");
+
+$null = "";
+
' +?> \ No newline at end of file From 2733341173c8a0a2b559612924f54283302d72a5 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez Date: Wed, 21 Dec 2022 07:35:47 +0100 Subject: [PATCH 2/4] new files added --- arrays.php | 37 +++++++++++++++++++++++++++++++++++++ maths.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 arrays.php create mode 100644 maths.php diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..d2d96bf --- /dev/null +++ b/arrays.php @@ -0,0 +1,37 @@ +"; + +function arrayMerge() { + return array_merge($animals, $numbers); +}; +print_r(array_merge($animals, $numbers)); +echo "
"; + +function lastElement($animals){ + return end($animals); +}; +echo end($animals); +echo "
"; + +function addElement($numbers){ + array_push($numbers, 5, 5.5); +}; +addElement($numbers); +print_r($numbers); + +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..72bf191 --- /dev/null +++ b/maths.php @@ -0,0 +1,41 @@ +"; + +function rounded($number) { +return ceil($number); +} +echo ceil($number); +echo "
"; + +$myArray = array(2,4,6,8,10,12); +function lowestValue($myArray) { + return min($myArray); +} +echo min($myArray); +echo "
"; + +function highestValue($myArray) { + return max($myArray); +} +echo max($myArray); +echo "
"; + +function random() { + return rand(1, 1000); +} +echo rand(1, 1000); +echo "
"; + +absolute($number); +rounded($number); +lowestValue($myArray); +highestValue($myArray); +random(); + +?> \ No newline at end of file From 682a9cb111babed4a1b206c05c4f4a231e130e15 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez Date: Wed, 21 Dec 2022 10:52:56 +0100 Subject: [PATCH 3/4] add files and changes --- arrays.php | 6 ++--- conditionals.php | 14 +++++------ functions.php | 46 +++++++++++++++++++++++++++++++++++ strings.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 functions.php create mode 100644 strings.php diff --git a/arrays.php b/arrays.php index d2d96bf..9bf89ae 100644 --- a/arrays.php +++ b/arrays.php @@ -28,10 +28,8 @@ function lastElement($animals){ echo end($animals); echo "
"; -function addElement($numbers){ - array_push($numbers, 5, 5.5); -}; -addElement($numbers); + +array_push($numbers, 5, 5.5); print_r($numbers); ?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php index a51ff5d..58f5cd0 100644 --- a/conditionals.php +++ b/conditionals.php @@ -37,31 +37,31 @@ $day = date("w"); switch($day) { - case $day == 1: + case 1: echo "Today is Monday :("; break; - case $day == 2: + case 2: echo "today is Tuesday :("; break; - case $day == 3: + case 3: echo "today is Wednesday :|"; break; - case $day == 4: + case 4: echo "today is Thursday :|"; break; - case $day == 5: + case 5: echo "today is Friday :)"; break; - case $day == 6: + case 6: echo "today is Saturday :D"; break; - case $day == 0: + case 0: echo "today is Sunday :)"; break; } diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..9e79091 --- /dev/null +++ b/functions.php @@ -0,0 +1,46 @@ +Create a function that given two numbers returns the sum of both"; + +function sum($a, $b) { + return $a + $b; +} +echo sum(14, 26); +echo "
"; + +echo "

Create a function that given two numbers returns the multiplication of both

"; + +function multiplication($a, $b) { + return $a * $b; +} +echo multiplication(14, 3); +echo "
"; + +echo "

Create a function that given two numbers returns the division of both

"; + +function division($a, $b) { + return $a / $b; +} +echo division(14, 3); +echo "
"; + +echo "

Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.

"; + +function operation($a, $operator, $b){ + if($operator == '+'){ + echo sum($a,$b); + }else if($operator == '*'){ + echo multiplication($a,$b); + }else if($operator == '/'){ + echo division($a,$b); + }else{ + echo "Error"; + } +} +operation(3, "+", 4); +echo "
"; +operation(3, "*", 4); +echo "
"; +operation(3, "/", 4); + +?> \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..0024351 --- /dev/null +++ b/strings.php @@ -0,0 +1,63 @@ +Print a text string"; + +print "example text"; +echo "
"; + +echo "

Print a text string that interpret variables

"; + +$city = "Madrid"; + +print $city; +echo "
"; + +echo "

Concatenate a previously declared variable in a text string

"; + +print $city. " (Spain)"; +echo "
"; + +echo "

Execute the function that allows you to replace text in a string (case sensitive)

"; + +echo "Hello world"; +echo "
"; +echo str_replace("Hello", "bye", "Hello world"); +echo "
"; + +echo "

Execute the function that allows you to replace text in a string (without taking into account upper / lower case)

"; + +echo "Hello world"; +echo "
"; +echo str_ireplace("hello", "bye", "hello world"); +echo "
"; + +echo "

Execute the function that allows you to write a text N times

"; + +echo str_repeat('Hello
', 7); +echo "
"; + +echo "

Execute the function that allows to obtain the length of a text string

"; + +$phrase = "Good morning everyone, have a good day"; +echo strlen($phrase); +echo "
"; + +echo "

Executes the function that allows to obtain the position of the first occurrence of a text within a text string

"; + +echo strpos($phrase, "morning"); +echo "
"; + +echo "

Execute the function that allows a text string to be capitalized

"; + +echo strtoupper($phrase); +echo "
"; + +echo "

Execute the function that allows you to transform a text string to lowercase

"; + +echo strtolower($phrase); +echo "
"; + +echo "

Execute the function that allows to obtain a text substring from a given position

"; + +echo substr($phrase, 0, 12); + +?> \ No newline at end of file From 2e8349c813384d3b43491971f12de0b55e0b2d7d Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez Date: Wed, 21 Dec 2022 11:01:18 +0100 Subject: [PATCH 4/4] add readme --- README.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7c787c3..e9a4f79 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ `#php` `#basics` `#master-in-software-development` -# PHP Basics +# PHP with Assembler

Version @@ -10,37 +10,23 @@ > > What distinguishes PHP from other languages ​​such as Javascript is that the code is executed on the server, generating HTML and sending it to the client. -## Index +## Index - [Requirements](#requirements) -- [Repository](#repository) - [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) - [Resources](#resources) ## Requirements - Learn the basics to program in PHP - Understand what a server-side language is and what it is used for +- Have a XAMPP software installed -## 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 ## 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)