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 - -

- Version -

+ -> In this project you will learn the basic notions of the famous PHP language which is so used in the world of web development. -> -> 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. +# PHP Basics -## Index +> In this project I learned the basic notions of PHP, language which is so used in the world of web development. -- [Requirements](#requirements) -- [Repository](#repository) -- [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) -- [Resources](#resources) +All the exercises have been done using PHP as language and using Xampp as web server. + +## What I've learned -## Requirements + -- Learn the basics to program in PHP -- Understand what a server-side language is and what it is used for +- Learn the basics to program in PHP. -## Repository +- What is a server-side language and what it is used for. -First of all you must fork this project into your GitHub account. +- What is **XAMPP** and how to use it. -To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. +- Improve GitHub knowledge. -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 +\* 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 October
"; + } else { + echo $month, "
"; + } + + #double condition + $minute = date("i"); + + if($minute < 10) { + echo "

the 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"), "
"; + + #current date in any format + echo "Current date: ", $dateVar->format('Y-m-d H:i:sP'), "
"; + + #current day + echo "Current day: ", date("l"), "
"; + + #current month in numerical format + echo "Month: ", date("m"), "
"; + + #current minute with leading zeros + echo "Current minute: ",date('i'); + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..4e66499 --- /dev/null +++ b/functions.php @@ -0,0 +1,39 @@ +Functions"; + + #function to sum two numbers + function sum($num1, $num2) { + return $num1 + $num2; + }; + + echo "

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 "
"; + + $arr = array("David", "Moina", 0 , 1); + + foreach($arr as $value) { + echo "$value
"; + } + + print "
"; + + $number = 0; + + while ($number <= 10) { + echo "$number "; + $number++; + } + + print "
"; + + $ej = 10; + + do { + echo "$ej "; + $ej--; + } while($ej > 0); + +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..31e554a --- /dev/null +++ b/maths.php @@ -0,0 +1,21 @@ +mathematical operators"; + + #absolute value + $absValue = abs(-5); + echo "

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 "

arithmetic operators

"; + + echo "5 + 5 = ",var_dump(5 + 5), "
"; + + echo "9 - 3 = ",var_dump(9 - 3), "
"; + + echo "3 * 10 = ",var_dump(3 * 10), "
"; + + echo "30 / 3 = ",var_dump(30 / 3), "
"; + + echo "20 % 2 = ",var_dump(20 % 2), "
"; + + #comparison operators + print "

comparison operators

"; + + echo "(1 == 2) = ",var_dump(5 + 5), "
"; + + echo "(4 != 5) = ",var_dump(4 != 5), "
"; + + echo "(3 < 5) = ",var_dump(3 < 5), "
"; + + echo "(3 > 5) = ",var_dump(3 > 5), "
"; + + echo "(5 <= 5) = ",var_dump(5 <= 5), "
"; + + echo "(5 >= 6) = ",var_dump(5 >= 6), "
"; + + #logical operators + print "

logical operators

"; + + $a = false; + $b = true; + + echo "a = false, b = true
"; + + echo "(a && b) = ", var_dump($a && $b), "
"; + + echo "(a and b) = ", var_dump($a and $b), "
"; + + echo "(a || b) = ", var_dump($a || $b), "
"; + + echo "(a or b) = ", var_dump($a or $b), "
"; + + echo "(!a) = ", var_dump(!$a), "
"; +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..3c20906 --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,5 @@ +PHP Info"; + + phpinfo(); +?> \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..604e37d --- /dev/null +++ b/print.php @@ -0,0 +1,11 @@ +Print"; + + echo "Its my first time with PHP
"; + + print "Hello my name is David
"; + + $a = array ('a' => 'manzana', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); + + print_r($a); +?> \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..630b49e --- /dev/null +++ b/strings.php @@ -0,0 +1,40 @@ +Strings"; + + echo "

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