├── README.md
├── arrays.php
├── conditionals.php
├── dates.php
├── functions.php
├── iterators.php
├── maths.php
├── operators.php
├── phpinfo.php
├── print.php
├── strings.php
└── types.php
/README.md:
--------------------------------------------------------------------------------
1 | `#php` `#basics` `#master-in-software-engineering`
2 |
3 | # PHP Basics
4 |
5 |
6 |
7 |
8 |
9 | > In this project you will learn the basic notions of the famous PHP language which is so used in the world of web development.
10 | >
11 | > 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.
12 |
13 | ## Index
14 |
15 | - [Requirements](#requirements)
16 | - [Repository](#repository)
17 | - [Technologies used](#technologies-used)
18 | - [Project delivery](#project-delivery)
19 | - [Resources](#resources)
20 |
21 | ## Requirements
22 |
23 | - Learn the basics to program in PHP
24 | - Understand what a server-side language is and what it is used for
25 |
26 | ## Repository
27 |
28 | First of all you must fork this project into your GitHub account.
29 |
30 | To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.
31 |
32 |
33 |
34 | ## Technologies used
35 |
36 | \* PHP
37 |
38 | ## Project delivery
39 |
40 | To deliver this project you must follow the steps indicated in the document:
41 |
42 | - [Submitting a solution](https://www.notion.so/Submitting-a-solution-524dab1a71dd4b96903f26385e24cdb6)
43 |
44 | ## Resources
45 |
46 | - [What can PHP do?](https://www.php.net/manual/es/intro-whatcando.php)
47 | - [Sample guide for README](https://gist.github.com/Villanuevand/6386899f70346d4580c723232524d35a)
48 | - [XAMPP](https://www.apachefriends.org/es/index.html)
49 | - [How to install XAMPP on Windows](https://www.youtube.com/watch?v=h6DEDm7C37A)
50 | - [What is a web server?](https://www.youtube.com/watch?v=Yt1nesKi5Ec)
51 | - [Web server basics](https://www.youtube.com/watch?v=3VqfpVKvlxQ)
52 |
--------------------------------------------------------------------------------
/arrays.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | //Define a simple array consisting of whole numbers and decimal numbers
9 | $array = array(1, 1.1, 2, 3.14);
10 | print_r($array);
11 | echo "
";
12 |
13 |
14 | //Define a multidimensional array
15 | $people = array(
16 | "Víctor" => array(
17 | "name" => "Víctor",
18 | "age" => "27",
19 | "country" => "Spain"
20 | ),
21 | "Juan" => array(
22 | "name" => "Juan",
23 | "age" => "25",
24 | "country" => "Spain"
25 | ),
26 | "Pedro" => array(
27 | "name" => "Pedro",
28 | "age" => "30",
29 | "country" => "Spain"
30 | )
31 | );
32 | print_r($people);
33 | echo "
";
34 |
35 |
36 | //Execute the function that allows to obtain the length of an array
37 | $array = array("Hello ", "Assembler ", "Team!");
38 | $arrayLength = count($array);
39 | print $arrayLength . "
";
40 |
41 | //Execute the function that allows to obtain the combination of two arrays
42 | $array1 = array("Hello ", "Assembler ", "Team!");
43 | $array2 = array("How ", "are ", "you?");
44 | $array3 = array_merge($array1, $array2);
45 | print_r($array3);
46 | echo "
";
47 |
48 |
49 | //Execute the function that once is given an array return the last element of it
50 | $array = array("Hello ", "Assembler ", "Team!");
51 | $lastElement = end($array);
52 | print $lastElement . "
";
53 |
54 |
55 | //Execute the function that once is given an array add a new element to the array in question
56 | $array = array("Hello ", "Assembler ", "Team!");
57 | array_push($array, ":)");
58 | print_r($array);
59 | echo "
";
60 |
--------------------------------------------------------------------------------
/conditionals.php:
--------------------------------------------------------------------------------
1 | "."We are in October";
16 | } else {
17 | echo "
"."We are in ".$month;
18 | }
19 |
20 |
21 | //Create a double condition that evaluates:
22 | // If the current minute is less than 10. Displays a message of type "the current minute is less than 10", if the current minute is greater than 15, displays a message of the type "the current minute is more than 15". If you do not meet any of the two conditions above: Displays a message of the type "does not meet any conditions”
23 | $currentMinute = getdate()['minutes'];
24 |
25 | if ($currentMinute < 10) {
26 | echo "
"."the current minute is less than 10";
27 | } elseif ($currentMinute > 15) {
28 | echo "
"."the current minute is more than 15";
29 | } else {
30 | echo "
"."does not meet any conditions";
31 | }
32 |
33 |
34 | //Create a switch type control structure to display a different message depending on the current day of the week.
35 | $day = getdate()['weekday'];
36 |
37 | switch($day) {
38 | case "Monday":
39 | echo "
"."Today is Monday";
40 | break;
41 | case "Tuesday":
42 | echo "
"."Today is Tuesday";
43 | break;
44 | case "Wednesday":
45 | echo "
"."Today is Wednesday";
46 | break;
47 | case "Thursday":
48 | echo "
"."Today is Thursday";
49 | break;
50 | case "Friday":
51 | echo "
"."Today is Friday";
52 | break;
53 | case "Saturday":
54 | echo "
"."Today is Saturday";
55 | break;
56 | case "Sunday":
57 | echo "
"."Today is Sunday";
58 | break;
59 | default:
60 | echo "
"."Not a valid day";
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/dates.php:
--------------------------------------------------------------------------------
1 | format('Y-m-d'). "
";
6 |
7 |
8 | //Get the current date in any format
9 | $currentDate = getdate();
10 | print_r($currentDate);
11 |
12 | //Get the current day
13 | $currentDay = getdate()['mday'];
14 | echo "
".$currentDay;
15 |
16 | // Get the current month in numerical format (1-12)
17 | $currentMonth = getdate()['mon'];
18 | echo "
".$currentMonth;
19 |
20 | //Get the current minute with leading zeros (00 - 59)
21 | $currentMinute = getdate()['minutes'];
22 | echo "
".$currentMinute;
23 |
--------------------------------------------------------------------------------
/functions.php:
--------------------------------------------------------------------------------
1 | ";
9 |
10 |
11 | //Create a function that given two numbers returns the multiplication of both
12 | function multiply($num1, $num2) {
13 | echo $num1 * $num2;
14 | }
15 | multiply(2, 3);
16 | echo "
";
17 |
18 |
19 | //Create a function that given two numbers returns the division of both
20 | function divide($num1, $num2) {
21 | echo $num1 / $num2;
22 | }
23 | divide(2, 3);
24 | echo "
";
25 | echo "
";
26 |
27 |
28 | //Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.
29 | function operation($num1, $num2, $operation) {
30 | if ($operation == "add") {
31 | echo $num1 + $num2;
32 | } elseif ($operation == "multiply") {
33 | echo $num1 * $num2;
34 | } elseif ($operation == "divide") {
35 | echo $num1 / $num2;
36 | }
37 | }
38 | operation(2, 3, "add");
39 | echo "
";
40 | operation(2, 3, "multiply");
41 | echo "
";
42 | operation(2, 3, "divide");
43 | echo "
";
44 |
45 |
--------------------------------------------------------------------------------
/iterators.php:
--------------------------------------------------------------------------------
1 | ";
6 | }
7 |
8 |
9 | //foreach loop
10 | $array = array("Hello ", "Assembler ", "Team!");
11 | foreach ($array as $value) {
12 | echo $value;
13 |
14 | }
15 |
16 | //while loop
17 | $i = 1;
18 | while ($i <= 10) {
19 | echo "
".$i;
20 | $i++;
21 | }
22 |
23 | // do while loop
24 | $i = 1;
25 | do {
26 | echo "
".$i;
27 | $i++;
28 | } while ($i <= 10);
--------------------------------------------------------------------------------
/maths.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 |
9 | //Define a variable whose value is the result of the function that returns a rounded value to the next highest integer.
10 | $x = 10.5;
11 | $y = ceil($x);
12 | echo $y."
";
13 |
14 | //Define a variable whose value is the result of the function that returns the highest value of a series of values that are received by parameter.
15 | $x = 10;
16 | $y = 20;
17 | $z = 30;
18 | $a = max($x, $y, $z);
19 | echo $a."
";
20 |
21 |
22 | //Define a variable whose value is the result of the function that returns the lowest value of a series of values that are received by parameter.
23 | $x = 10;
24 | $y = 20;
25 | $z = 30;
26 | $a = min($x, $y, $z);
27 | echo $a."
";
28 |
29 | //Define a variable whose value is the result of the function that returns a random number
30 | $x = rand(1, 10);
31 | echo $x."
";
32 |
--------------------------------------------------------------------------------
/operators.php:
--------------------------------------------------------------------------------
1 | ";
10 |
11 | // - operator
12 | $x = 10;
13 | $y = 20;
14 | $z = $x - $y;
15 | echo $z."
";
16 |
17 | // "*" operator
18 | $x = 10;
19 | $y = 20;
20 | $z = $x * $y;
21 | echo $z."
";
22 |
23 | // "/" operator
24 | $x = 10;
25 | $y = 20;
26 | $z = $x / $y;
27 | echo $z."
";
28 |
29 | // "%" operator
30 | $x = 10;
31 | $y = 20;
32 | $z = $x % $y;
33 | echo $z."
";
34 |
35 |
36 | // COMPARISON OPERATORS(==,! =, <,>, <=,> =)
37 |
38 | $x = 10;
39 | $y = 20;
40 |
41 | $x == $y;
42 | $x != $y;
43 | $x < $y;
44 | $x > $y;
45 | $x <= $y;
46 | $x >= $y;
47 |
48 | var_dump($x == $y);
49 | var_dump($x != $y);
50 | var_dump($x < $y);
51 | var_dump($x > $y);
52 | var_dump($x <= $y);
53 | var_dump($x >= $y);
54 |
55 |
56 | // LOGICAL OPERATORS(&&, ||, !, Xor)
57 |
58 | $x = true;
59 | $y = false;
60 |
61 | $x && $y;
62 | $x || $y;
63 | !$x;
64 | $x xor $y;
65 |
66 | echo "
";
67 |
68 | var_dump($x && $y);
69 | var_dump($x || $y);
70 | var_dump(!$x);
71 | var_dump($x xor $y);
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/phpinfo.php:
--------------------------------------------------------------------------------
1 | " ;
5 |
6 |
7 |
8 | //print: we can only return one string per line
9 | print "Hello Assembler Team! ";
10 | print "How are you? ";
11 | print "Let's code!
";
12 |
13 |
14 | //print_r: accepts other data types as well, such as arrays
15 | $array = array("Hello", "Assembler", "Team!");
16 | print_r($array);
17 |
18 |
--------------------------------------------------------------------------------
/strings.php:
--------------------------------------------------------------------------------
1 | ";
5 |
6 | //Print a text string that interpret variables
7 | print "Hello Assembler Team! " . "How are you? " . "Let's code!
";
8 |
9 | //Concatenate a previously declared variable in a text string
10 | $text1 = "Hello Assembler Team! ";
11 | $text2 = "How are you? ";
12 | $text3 = "Let's code!
";
13 | print $text1 . $text2 . $text3;
14 |
15 |
16 | //Execute the function that allows you to replace text in a string (case sensitive)
17 | $text = "Hello Assembler TEAM! ";
18 | $text = str_replace("e", "", $text);
19 | $text = str_replace("Team!", "", $text);
20 | print $text . "
";
21 |
22 |
23 | //Execute the function that allows you to replace text in a string (without taking into account upper / lower case)
24 | $text = "Hello Assembler Team! ";
25 | $text = str_ireplace("e", "", $text);
26 | $text = str_ireplace("Team!", "", $text);
27 | print $text. "
";
28 |
29 |
30 | //Execute the function that allows you to write a text N times
31 | $text = "Hello Assembler Team! ";
32 | $text = str_repeat($text, 3);
33 | print $text . "
";
34 |
35 | //Execute the function that allows to obtain the length of a text string
36 | $text = "Hello Assembler Team! ";
37 | $text = strlen($text);
38 | print $text . "
";
39 |
40 | //Executes the function that allows to obtain the position of the first occurrence of a text within a text string
41 | $text = "Hello Assembler Team! ";
42 | $text = strpos($text, "Assembler");
43 | print $text . "
";
44 |
45 | //Execute the function that allows a text string to be capitalized
46 | $text = "Hello Assembler Team! ";
47 | $text = strtoupper($text);
48 | print $text . "
";
49 |
50 |
51 | //Execute the function that allows you to transform a text string to lowercase
52 | $text = "HELLO ASSEMBLER TEAM! ";
53 | $text = strtolower($text);
54 | print $text . "
";
55 |
56 |
57 | //Execute the function that allows to obtain a text substring from a given position
58 | $text = "Hello Assembler Team! ";
59 | $text = substr($text, 0, 5);
60 | print $text . "
";
61 |
62 |
--------------------------------------------------------------------------------
/types.php:
--------------------------------------------------------------------------------
1 | ");
9 | $obj = (object) array("name" => "Víctor");
10 | $null = null;
11 |
12 | var_dump($boolean);
13 | var_dump($integer);
14 | var_dump($float);
15 | var_dump($string);
16 | var_dump($array);
17 | var_dump($obj);
18 | var_dump($null);
19 |
--------------------------------------------------------------------------------