diff --git a/README.md b/README.md index 7c787c3..4afb85d 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,48 @@ -`#php` `#basics` `#master-in-software-development` +# PHP practice with the Assembler school -# PHP Basics -

- Version -

+## Starting 🚀 -> 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. +These instructions will allow you to get a working copy of the project on your premises for development and testing purposes. -## Index -- [Requirements](#requirements) -- [Repository](#repository) -- [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) -- [Resources](#resources) -## Requirements +### Prerequirements 📋 -- Learn the basics to program in PHP -- Understand what a server-side language is and what it is used for +XAMPP software installation -## 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. +### Installing 🔧 -Fork on GitHub +- [Guide to install XAMPP](https://www.php.net/manual/es/intro-whatcando.php) -## Technologies used +When you have installed XAMPP follow the steps below. +1 - clone repository. +2 - save the repository in the folder on drive C: > xampp > htdocs. -\* 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" +## Running the tests ⚙️ + +To view the file, type the following in your browser: +#### localhost/folder-name + + + + +## Built With 🛠️ + + +* [PHP](https://www.php.net/) + + + + +## Authors ✒️ + +* **Jose Torres** - [88jose](https://github.com/88jose) + + -## Resources -- [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) diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..b5ac8f0 --- /dev/null +++ b/arrays.php @@ -0,0 +1,59 @@ + + + + + + + PHP Arrays + + +

Arrays.php

+ Create a simple string array
$string = ["Juan", "Pepe", "Mario"]
'; + $string = ['Juan', 'Pepe', 'Mario']; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Create a simple numbers array
$numbers = [5, 8.1, 258, 35.9]
'; + $numbers = [5, 8.1, 258, 35.9]; + echo '
';
+        var_dump($numbers);
+        echo '
'; + + echo 'Create a nested array
$nested = [[5, 8.1, 258, 35.9],["Juan", "Pepe", "Mario"]]
'; + $nested = [[5, 8.1, 258, 35.9],['Juan', 'Pepe', 'Mario']]; + echo '
';
+        var_dump($nested);
+        echo '
'; + + echo 'Create a nested array
'; + echo ' Array length: ' . count($string) . '
count($string)'; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Combine arrays
$result = array_merge($numbers, $nested)'; + $result = array_merge($numbers, $nested); + echo '
';
+        var_dump($result);
+        echo '
'; + + echo 'Get last position of an array
end($string)
'; + echo ' Last position: ' . end($string) . ''; + echo '
';
+        var_dump($string);
+        echo '
'; + + echo 'Add elements to array
array_push($string, "Carlos", "Julio")
'; + echo ' Added Carlos and Julio'; + array_push($string, 'Carlos', 'Julio'); + echo '
';
+        var_dump($string);
+        echo '
'; + + + + ?> + + \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..0bde2e4 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,72 @@ + + + + + + + PHP Conditionals + + +

Iterators.php

+ Today is Monday?

'; + if($fecha->format('w') === 1){ + echo "We are on Monday"; + }else{ + echo "Today is not Monday"; + } + + echo '

Are we in October?

'; + if($fecha->format('M') === 'Oct'){ + echo "We are in October"; + }else{ + echo "We are not October"; + } + + echo '

Is the current minute less than 10?

'; + if($fecha->format('i') < 10){ + echo "The current minute is less than 10"; + }else if($fecha->format('i') > 15){ + echo "The current minute is more than 15"; + }else{ + echo "Does not meet any conditions"; + } + + + echo '

What weekday is today?

'; + switch($fecha->format('l')){ + case 'Sunday': + echo "Today is Sunday"; + break; + + case 'Monday': + echo "Today is Monday"; + break; + + case 'Tuesday': + echo "Today is Tuesday"; + break; + + case 'Wenesday': + echo "Today is Wenesday"; + break; + + case 'Thursday': + echo "Today is Thursday"; + break; + + case 'Friday': + echo "Today is Friday"; + break; + + case 'Friday': + echo "Today is Friday"; + break; + + default: "There are no more days of the week"; + } + ?> + + \ No newline at end of file diff --git a/date.php b/date.php new file mode 100644 index 0000000..6ff2a3a --- /dev/null +++ b/date.php @@ -0,0 +1,25 @@ + + + + + + + PHP Date + + +

Date.php

+ Current date Europe/Madrid:

'; + echo '
';
+    var_dump($fecha);
+    echo '

'; + echo '

Current date: '. $fecha->format('Y-m-d') . '

'; + echo '

Current day: ' . $fecha->format('d') . '

'; + echo '

Current month: ' . $fecha->format('m') . '

'; + echo '

Current minuts: '. $fecha->format('00:i') . '

'; + + ?> + + + \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..080c7fd --- /dev/null +++ b/functions.php @@ -0,0 +1,49 @@ + + + + + + + PHP Functions + + +

Functions.php

+ + Function add
'; + function add($num1, $num2){ + return $num1 + $num2; + } + echo add(20, 30) . '
'; + + echo 'Function multiply
'; + function multiply($num1, $num2){ + return $num1 * $num2; + } + echo multiply(20, 30) . '
'; + + echo 'Function division
'; + function division($num1, $num2){ + echo $num1 / $num2; + } + division(50, 30) . '

'; + + echo '

'; + echo 'Function operation
'; + function operation($num1, $operator, $num2){ + if($operator === '+'){ + echo 'Add: ' . $num1 + $num2 . '
'; + }else if($operator === '*'){ + echo 'Multilply: ' . $num1 * $num2 . '
'; + }else if($operator === '/'){ + echo 'Division: ' . $num1 / $num2 . '
'; + }else{ + echo "Error"; + } + } + operation(70, '+' , 20) . '
'; + operation(11, '*' , 4) . '
'; + operation(65, '/' , 20) . '
'; + ?> + + \ No newline at end of file diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..77d2765 --- /dev/null +++ b/iterators.php @@ -0,0 +1,52 @@ + + + + + + + PHP Iterators + + +

Iterators.php

+ 1- Iterating with the for loop through an array of strings

+ '; + + echo '

2- Iterating with the foreach loop through an array of strings

+ '; + + echo '

3- Iterating with the while loop through an array of numbers

+ '; + while($count < count($numbers)){ + echo '' ; + $count++; + } + echo '
' . $numbers[$count] . '
'; + + echo '

4- Iterating with the do while loop through an array of numbers

+ '; + do { + echo ''; + $num1++; + } while ($num1 <= 10); + echo '
' . $num1 .'
'; + + + + ?> + + + \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..ae634fb --- /dev/null +++ b/maths.php @@ -0,0 +1,28 @@ + + + + + + + PHP Maths + + +

Maths.php

+ $num1 = 95.52
'; + $num1 = 95.52; + echo 'Absolute value: ' . abs($num1) . '
'; + echo 'Rounded down value: ' . floor($num1) . '
'; + echo 'Rounded up value: ' . round($num1) . '

'; + + echo '$numbers = array (0.8, 9.5, 1, 25);
'; + $numbers = array(0.8, 9.5, 1, 25); + echo 'Highest value: ' . max($numbers) . '
'; + echo 'Lowest value: ' . min($numbers) . '

'; + + echo 'Random number from 0 to 40
'; + echo 'Random value: ' . rand(0, 40) . '
'; + + ?> + + \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..b6e2651 --- /dev/null +++ b/operators.php @@ -0,0 +1,110 @@ + + + + + + + PHP Operators + + +

Operators.php

+ operator +

'; + echo '$num1 = 12
$num2 = 4
'; + $sum = $num1 + $num2; + echo $sum . '
'; + echo 'var_dump($num1 + $num2)
'; + var_dump($sum); + echo '
'; + + echo '

operator -

'; + echo '$num1 = 12
$num2 = 4
'; + $rest = $num1 - $num2; + echo $rest . '
'; + echo 'var_dump($num1 - $num2)
'; + var_dump($rest); + echo '
'; + + echo '

operator /

'; + echo '$num1 = 12
$num2 = 4
'; + $div = $num1 / $num2; + echo $div . '
'; + echo 'var_dump($num1 / $num2)
'; + var_dump($div); + echo '
'; + + echo '

operator *

'; + echo '$num1 = 12
$num2 = 4
'; + $mult = $num1 * $num2; + echo $mult . '
'; + echo 'var_dump($num1 * $num2)
'; + var_dump($mult); + echo '
'; + + echo '

operator %

'; + echo '$num1 = 12
$num2 = 4
'; + $res = $num1 % $num2; + echo $res . '
'; + echo 'var_dump($num1 % $num2)
'; + var_dump($res); + echo '
'; + + echo '

operator ==

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 == $num2)
'; + var_dump($num1 == $num2); + echo '
'; + + echo '

operator !=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 != $num2)
'; + var_dump($num1 != $num2); + echo '
'; + + echo '

operator <

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < $num2)
'; + var_dump($num1 < $num2); + echo '
'; + + echo '

operator >

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 > $num2)
'; + var_dump($num1 > $num2); + echo '
'; + + echo '

operator <=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 <= $num2)
'; + var_dump($num1 <= $num2); + echo '
'; + + echo '

operator >=

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 >= $num2)
'; + var_dump($num1 >= $num2); + echo '
'; + + echo '

operator &&

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < 20 && $num2 > 1)
'; + var_dump($num1 < 20 && $num2 > 1); + echo '
'; + + echo '

operator ||

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 < 20 || $num2 > 1)
'; + var_dump($num1 < 20 || $num2 > 1); + echo '
'; + + echo '

operator Xor

'; + echo '$num1 = 12
$num2 = 4
'; + echo 'var_dump($num1 ^ $num2)
'; + var_dump($num1 ^ $num2); + + ?> + + \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..bc82da6 --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/phpinfo/index.php b/phpinfo/index.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/phpinfo/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..c6e3128 --- /dev/null +++ b/print.php @@ -0,0 +1,26 @@ + + + + + + + PHP Print and Echo + + +

Print.php

+ Display variables with echo statement: ' . $name . " " .$surname .'

'; + + print '

Display variable with print statement: '. $name .'

'; + echo '
'; + + echo '

Show nested array with print_r statement

'; + echo '
';
+        $compra = array ('verdura' => array ('pimiento', 'calabaza', 'berengena'), 'fruta' => array ('pera', 'manzana', 'uvas'));
+        print_r($compra);
+        echo '
'; + ?> + + diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..cfb8ada --- /dev/null +++ b/strings.php @@ -0,0 +1,47 @@ + + + + + + + PHP Strings + + +

Strings.php

+ Print a text string: "I am a text string"

'; + + $phrase = 'Today is a good day'; + echo 'Print phrase with variables: ' . $phrase . '

'; + + $name = 'Jose'; + $surname = 'Torres'; + echo 'Print sentence with concatenated variables: My name is: ' . $name . ' my surname is: '. $surname .'

'; + + echo 'Replace text
'; + echo 'Hello world! Today is a great day
'; + echo str_replace('world', 'Jose', 'Hello world!') . '

'; + + echo 'Repeat text 10 times:
'; + echo str_repeat('Hi!
', 10); + + echo '
Know the number of characters that the string of the variable has: $phrase = "Today is a good day";
'; + echo strlen($phrase); + + echo '

Position of a word: $phrase = "Today is a good day";
'; + echo strpos($phrase, 'good'); + + echo '

Convert text string to uppercase: $phrase = "Today is a good day";
'; + echo strtoupper($phrase); + + echo '

Convert text string to lowercase: $phrase = "Today is a good day";
'; + echo strtolower($phrase); + + echo '

Get substring of text
'; + echo substr($phrase, 0, 4); + + + ?> + + \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..d7338fb --- /dev/null +++ b/types.php @@ -0,0 +1,49 @@ + + + + + + + PHP Types + + +

Types.php

+ $boolean = [true, false]

'; + $boolean = [true, false]; + var_dump($boolean); + echo '
'; + + echo '

$integer = 1

'; + $integer = 1; + var_dump($integer); + echo '
'; + + echo '

$float = 1.5

'; + $float = 1.5; + var_dump($float); + echo '
'; + + echo '

$string = "Jose"

'; + $string = 'Jose'; + var_dump($string); + echo '
'; + + echo '

$array = array("Jose", 1, 1.5)

'; + $array = array('Jose', 1, 1.5); + echo '
';
+        var_dump($array);
+        echo '

'; + + echo '

$object = (object)["fruta" => "pera","manzana", "verdura" => "zanahoria","calabaza"]

'; + $object = (object)["fruta" => "pera","manzana", "verdura" => "zanahoria","calabaza"]; + echo '
';
+        var_dump($object);
+        echo '
'; + + echo '

$null = NULL

'; + $null = NULL; + var_dump($null); + ?> + + \ No newline at end of file