diff --git a/README.md b/README.md index 7c787c3..4880247 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,41 @@ -`#php` `#basics` `#master-in-software-development` +# PHP Basics đź’» -# 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. +> In this project we learnt the basic notions of PHP which is widely 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. ## Index - [Requirements](#requirements) -- [Repository](#repository) - [Technologies used](#technologies-used) -- [Project delivery](#project-delivery) - [Resources](#resources) ## Requirements - Learn the basics to program in PHP +- Installing and using XAMPP +- Navigate to htdocs and create all files to appear on localserver - Understand what a server-side language is and what it is used for -## Repository - -First of all you must fork this project into your GitHub account. +## Screen Captures of Xampp -To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. +

Welcome Page XAMPP

+

+xampp1 +

-Fork on GitHub +

XAMPP Apache

+

+xampp2 +

## 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" +\* Xampp +\* VSCode ## 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..d8ae8b9 --- /dev/null +++ b/arrays.php @@ -0,0 +1,32 @@ +"; +$arrayStrings = array("apple", "pear", "banana"); +print_r($arrayStrings); +echo "

"; + +echo "Regular array with numbers:
"; +$arrayNums = array(1, 2, 4.1231); +print_r($arrayNums); +echo "

"; + +echo "Multidimensional array:
"; +$arrayMultiDim = array(array("Volvo", 1), array("Seat", 2), array("Porsche", 0)); +print_r($arrayMultiDim); +echo "

"; + +echo "Length of array:
"; +echo count($arrayStrings); +echo "

"; + +echo "Combination of two arrays:
"; +print_r(array_merge($arrayStrings, $arrayNums)); +echo "

"; + +echo "Return last element of array:
"; +echo (end($arrayNums)) . "

"; + +echo "Add element to array (2, 4):
"; +array_push($arrayStrings, 2, 4); +print_r($arrayStrings); +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..547a5f0 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,73 @@ +
"; + +if ($day == "Monday") { + echo "We are on Monday"; +} + +echo "


"; + +#Simple condition with Date + +$month = date("F"); + +echo "Month is date('F'): $month

"; + +if ($month == "October"){ + echo "We are in October
"; +} else { + echo "We are in $month


"; +} + +#Double conditions + +$minute = date("i"); + +echo "Minute is: $minute

"; + +if ($minute < 10){ + echo "the current minute is less than 10

"; +} else if ($minute > 15) { + echo "the current minute is more than 15

"; +} else { + echo "does not meet any conditions

"; +} + +echo "

"; + +#Switch statement + +$dayOfTheWeek = date("l"); + +echo "The day of the week is: $dayOfTheWeek

"; + +switch ($dayOfTheWeek){ + case "Monday": + echo "I eat potatoes

"; + break; + case "Tuesday": + echo "I play the guitar

"; + break; + case "Wednesday": + echo "I eat a lot of cheese :)

"; + break; + case "Thursday": + echo "My cat destroys the Christmas Tree

"; + break; + case "Friday": + echo "Hola Wilson

"; + break; + case "Saturday": + echo "My name is Jeff
"; + break; + case "Sunday": + echo "Paella para todos

"; + break; +} + +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..bf86f7c --- /dev/null +++ b/dates.php @@ -0,0 +1,43 @@ +
"; + +echo "Today is " . date("Y-m-d"); + +echo "


"; + +#Date time argument "Y-m-d" + +echo "Date with any format 'Y/m/d/l':

"; + +echo "Today is " . date("Y/m/d/l"); + +echo "


"; + +#Get Current Day + +echo "Current day 'l':

"; + +echo "Today is " . date("l"); + +echo "


"; + +#Get Current Month in numerical Format + +echo "Current Month in numerical Format 'm':

"; + +echo "Today is " . date("m"); + +echo "


"; + +#Get current minutes with Leading zeros + +echo "Current Minutes with leading zeros 'i':

"; + +echo "Current minute: " . date("i"); + +echo "


"; + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..c851a0d --- /dev/null +++ b/functions.php @@ -0,0 +1,45 @@ +"; + +function sum ($x, $y){ + return $x + $y; +} +echo (sum(1, 2)); + +echo "

"; + +echo "Function that returns the multiplication of 2 values (3, 5):
"; + +function mul ($x, $y){ + return $x * $y; +} +echo mul(3, 5); + +echo "

"; + +echo "Function that returns the division of 2 values (15, 5):
"; + +function div ($x, $y){ + return $x / $y; +} +echo div(15, 5); + +echo "

"; + +echo "Function that returns the operation of 2 values depending on operation input ('add', 'multiply') (3, 5):
"; + +function operation ($x, $y, $operation){ + if ($operation == "add"){ + return $x + $y; + } else if($operation == "multiply"){ + return $x * $y; + } +} +echo operation(3, 5, "add"); +echo "
"; +echo operation(3, 5, "multiply"); + +echo "

"; + +?> \ No newline at end of file diff --git a/img/xampp1.jpeg b/img/xampp1.jpeg new file mode 100644 index 0000000..2bf8d46 Binary files /dev/null and b/img/xampp1.jpeg differ diff --git a/img/xampp2.jpeg b/img/xampp2.jpeg new file mode 100644 index 0000000..3f33b02 Binary files /dev/null and b/img/xampp2.jpeg differ diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..35c0300 --- /dev/null +++ b/iterators.php @@ -0,0 +1,48 @@ +
"; + +for($i = 0; $i < 10; $i++) { + echo $i; +} +echo "


"; + +#forEach Loop + +echo "- foreach Loop in PHP:

"; + +$fruits = array("Apple", "Orange", "Banana", "Kiwi"); + +foreach ($fruits as $fruit) { + echo "$fruit
"; +} + +echo "

"; + +#while Loop + +echo "- while Loop in PHP:

"; + +$j = 0; + +while ($j < 10) { + echo $j; + $j++; +} + +echo "


"; + +#do while Loop + +echo "- do while Loop in PHP:

"; + +$k = 0; + +do { + echo $k; + $k++; +} while ($k < 10); + +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..5af7146 --- /dev/null +++ b/maths.php @@ -0,0 +1,48 @@ +
"; + +$absNum = -4.5; +echo "Number: $absNum
"; + +var_dump(abs($absNum)); + +echo "


"; + +#Rounded Function + +echo "This is the rounded function:

"; + +$roundedNum = 4.52343; +echo "Number to round: $roundedNum
"; + +var_dump(round($roundedNum)); + +echo "


"; + +#Highest Value Function +echo "This is the highest value function:

"; + +$array = array(4, 5, 12, 23, 2, 1); +echo "Array to do highest value:
"; +print_r($array); +echo "

"; + +echo "Max function: "; +echo max($array); + +echo "


"; + +echo "Min function: "; +echo min($array); + +echo "


"; + +echo "This is the random value function:

"; + +$random = rand(); +echo "$random"; + +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..9f4ab49 --- /dev/null +++ b/operators.php @@ -0,0 +1,35 @@ +", "b = $b
"; + +echo "

"; + +#Arithmetic Operators +echo "Arithmetic Operators:

"; + +echo "1: + , 2: - , 3: * , 4: / , 5: %
"; + +var_dump($a + $b, $a - $b, $a * $b, $a / $b, $a % $b); + +echo "


"; + +#Comparison Operators +echo "Comparison Operators:

"; + +echo "1: == , 2: != , 3: < , 4: > , 5: <=, 6: >=
"; + +var_dump($a == $b, $a != $b, $a < $b, $a > $b, $a <= $b, $a >= $b); + +echo "


"; + +#Logical Operators +echo "Logical Operators:

"; + +echo "1: && , 2: and , 3: || , 4: or , 5: !, 6: xor
"; + +var_dump($a == 10 && $b == 5, $a == 10 and $b == 5, $a == 10 || $b == 10, $a == 10 or $b == 5, !$a == 5, $a == 10 xor $b == 10); + +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..6480abf --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..a23b316 --- /dev/null +++ b/print.php @@ -0,0 +1,29 @@ +
"; + +echo "Hello World, my name is Pepe
", "and I'm 28 years old.

"; + +echo "
"; + +#Instruction with "print" + +echo "- print in PHP:

"; + +print "I like playing the guitar!

"; + +echo "
"; + +#Instruction with "print_r" + +echo "- print_r in PHP:

"; + +$array = array("Red", "Orange", "Yellow"); + +print_r($array[1]); + +echo "
"; + +?> \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..4576a20 --- /dev/null +++ b/strings.php @@ -0,0 +1,46 @@ +"; +var_dump($b); +echo "

"; +echo "Printing a string:
"; +echo "This is a string

"; + +echo "Printing a string with variables:
"; +echo "I have $a $b in my bag

"; + +echo "Concatenating a previously declared variable:
"; +echo "I have $a " . $b . "

"; + +echo "Replace string: 'Hello world!' with Peter instead of world.
"; +echo str_replace("world","Peter","Hello world!") . "

"; + + +echo "Replace string: 'Hello World!' with Peter instead of World but putting 'world' as parameter.
"; +echo str_ireplace("world","Peter","Hello World!") . "

"; + +echo "Writing a text N times (5):
"; +echo str_repeat("Hello
", 5) . "
"; + +echo "Get the length of a string (apples):
"; +echo strlen($b). "

"; + +echo "Position of the first occurrence of a text within a text string:
"; +echo strpos("I love php, I love php too!", "php"); + +echo "

"; + +echo "Capitalize string (hello):
"; +echo ucfirst("hello world!") . "

"; + +echo "Turn to lower case (hellO WORld!):
"; +echo strtolower("hellO WORld!") . "

"; + +echo "Get substring (Hello World! , 3):
"; +echo substr("Hello World!",3) . "

"; + +?> \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..f8916c6 --- /dev/null +++ b/types.php @@ -0,0 +1,69 @@ +
"; + +$a = true; +$b = false; + +var_dump($a, $b); +echo "

"; + +#Integer + +echo "This is integer type:

"; + +$c = 5; + +var_dump($c); +echo "

"; + +#Float + +echo "This is a float type:

"; + +$d = 10.232423; + +var_dump($d); +echo "

"; + +#string + +echo "This is a string:

"; + +$e = "Hello Wilson
"; +var_dump($e); + +echo "

"; + +#array + +echo "This is an array:

"; + +$array = array( + "foo" => "var", + "bar" => "foo", +); + +var_dump($array); +echo "

"; + +#object + +echo "This is an object:

"; + +$object = (object)array("tedi"=>"bear"); + +var_dump($object); +echo "

"; + +#NULL + +echo "This is NULL:

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