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) diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..9bf89ae --- /dev/null +++ b/arrays.php @@ -0,0 +1,35 @@ +"; + +function arrayMerge() { + return array_merge($animals, $numbers); +}; +print_r(array_merge($animals, $numbers)); +echo "
"; + +function lastElement($animals){ + return end($animals); +}; +echo end($animals); +echo "
"; + + +array_push($numbers, 5, 5.5); +print_r($numbers); + +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..58f5cd0 --- /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 1: + echo "Today is Monday :("; + break; + + case 2: + echo "today is Tuesday :("; + break; + + case 3: + echo "today is Wednesday :|"; + break; + + case 4: + echo "today is Thursday :|"; + break; + + case 5: + echo "today is Friday :)"; + break; + + case 6: + echo "today is Saturday :D"; + break; + + case 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/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/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/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 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/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 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