From fcd17d0d93bf7337ff8f3955654b0ff32f56426d Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Mon, 19 Dec 2022 17:09:36 +0100 Subject: [PATCH 1/7] Finish php --- print.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 print.php diff --git a/print.php b/print.php new file mode 100644 index 0000000..f1192c0 --- /dev/null +++ b/print.php @@ -0,0 +1,10 @@ +"); + +echo ("Hello World
"); + +$a = array("a" => "red", "b" => "blue", "c" => "green"); +print_r($a); + +?> \ No newline at end of file From 5b5ca2934da8ec1a2867b8bacbeeb593ac5a69cc Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Mon, 19 Dec 2022 17:33:03 +0100 Subject: [PATCH 2/7] Not finished --- iterators.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 iterators.php diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..3d00d5b --- /dev/null +++ b/iterators.php @@ -0,0 +1,24 @@ + 0); + + +?> \ No newline at end of file From 002aec835cd83f21190647a296d48c2905c9a5bb Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Mon, 19 Dec 2022 19:06:05 +0100 Subject: [PATCH 3/7] Tomorrow more --- arrays.php | 3 +++ conditionals.php | 3 +++ dates.php | 21 +++++++++++++++++++++ functions.php | 3 +++ iterators.php | 20 ++++++++++++++++---- maths.php | 3 +++ operators.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ phpinfo.php | 3 +++ strings.php | 3 +++ types.php | 3 +++ 10 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 arrays.php create mode 100644 conditionals.php create mode 100644 dates.php create mode 100644 functions.php create mode 100644 maths.php create mode 100644 operators.php create mode 100644 phpinfo.php create mode 100644 strings.php create mode 100644 types.php diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/arrays.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/conditionals.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..3e6a715 --- /dev/null +++ b/dates.php @@ -0,0 +1,21 @@ +
"; + +echo date(DATE_RFC2822); + +echo "

"; + +echo date("l"); + +echo "

"; + +echo date("m"); + +echo "

"; + +echo date("i"); + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/functions.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/iterators.php b/iterators.php index 3d00d5b..173c8e4 100644 --- a/iterators.php +++ b/iterators.php @@ -1,21 +1,33 @@
"; + $array = array(1, 2, 3, 4); foreach ($array as &$valor) { - $valor = $valor * 2; + $valor = $valor * 2; + echo "Valor de $valor
"; } -while ($i <= 10) { - echo $i++; +echo "

"; + +$y = 1; + +while ($y <= 10) { + echo $y; + $y++; } +echo "

"; + +$x = 0; + do { echo $x; } while ($x > 0); diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/maths.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..27add24 --- /dev/null +++ b/operators.php @@ -0,0 +1,48 @@ +"; +echo ($a - $b); +echo "
"; +echo ($a * $b); +echo "
"; +echo ($a / $b); +echo "
"; +echo ($a % $b); + +var_dump($a == $b); + +echo "
"; +echo ($a == $b); +echo "
"; +echo ($a != $b); +echo "
"; +echo ($a < $b); +echo "
"; +echo ($a > $b); +echo "
"; +echo ($a <= $b); +echo "
"; +echo ($a >= $b); + +var_dump($a == $b); + +echo "
"; +echo ($a && $b); +echo "
"; +echo ($a and $b); +echo "
"; +echo ($a || $b); +echo "
"; +echo ($a or $b); +echo "
"; +echo (! $b); +echo "
"; +echo ($a xor $b); + +var_dump($a == $b); + +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/strings.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/types.php @@ -0,0 +1,3 @@ + \ No newline at end of file From 155425b49a76b0cd464dd5cd733f24e7295f433f Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Tue, 20 Dec 2022 10:14:32 +0100 Subject: [PATCH 4/7] Finished conditionals and operators --- conditionals.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ operators.php | 45 +++++-------------------------- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/conditionals.php b/conditionals.php index 15c5adc..ad15678 100644 --- a/conditionals.php +++ b/conditionals.php @@ -1,3 +1,73 @@
"; + +/* Punto 2 */ + +$b = date("F"); + +if($b == "October") { + echo "We are in October"; +} else { + echo "We are on $b"; +} + +echo "

"; + +/* PUNTO 3 */ + +$c = date("i"); + +if($c <= "10") { + echo "The current minute is less than 10"; +} elseif($c >= "16") { + echo "The current minute is more than 15"; +} else { + echo "does not meet any conditions"; +} + +echo "

"; + +/* PUNTO 4 */ + +$day = date("l"); + +switch($day) { + + case "Monday"; + echo "Today is Monday"; + break; + + case "Tuesday"; + echo "Today is Tuesday"; + break; + + case "Wednesday"; + echo "Today is Wednesday"; + break; + + case "Thursday"; + echo "Today is Thursday"; + break; + + case "Friday"; + echo "Today is Friday"; + break; + + case "Saturday"; + echo "Today is Saturday"; + break; + + default: echo "Today is the las day of the week"; + +} + + + ?> \ No newline at end of file diff --git a/operators.php b/operators.php index 27add24..d6af941 100644 --- a/operators.php +++ b/operators.php @@ -3,46 +3,15 @@ $a = 4; $b = 7; -echo ($a + $b); -echo "
"; -echo ($a - $b); -echo "
"; -echo ($a * $b); -echo "
"; -echo ($a / $b); -echo "
"; -echo ($a % $b); - -var_dump($a == $b); - -echo "
"; +var_dump($a + $b, $a - $b, $a * $b, $a / $b, $a % $b); echo ($a == $b); -echo "
"; -echo ($a != $b); -echo "
"; -echo ($a < $b); -echo "
"; -echo ($a > $b); -echo "
"; -echo ($a <= $b); -echo "
"; -echo ($a >= $b); - -var_dump($a == $b); +echo "

"; -echo "
"; -echo ($a && $b); -echo "
"; -echo ($a and $b); -echo "
"; -echo ($a || $b); -echo "
"; -echo ($a or $b); -echo "
"; -echo (! $b); -echo "
"; -echo ($a xor $b); +var_dump($a == $b,$a != $b,$a < $b,$a > $b,$a <= $b,$a >= $b); +echo ($a == $b); +echo "

"; -var_dump($a == $b); +var_dump($a && $b,$a and $b,$a || $b,$a or $b,! $b,$a xor $b); +echo ($a == $b); ?> \ No newline at end of file From 9658970f7b272bd1d12287b9691b533e45bad350 Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Tue, 20 Dec 2022 11:38:26 +0100 Subject: [PATCH 5/7] End of maths, strings and types !! --- maths.php | 41 +++++++++++++++++++++++++++++++ strings.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ types.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) diff --git a/maths.php b/maths.php index 15c5adc..1c9585f 100644 --- a/maths.php +++ b/maths.php @@ -1,3 +1,44 @@ "; +echo abs(5); +echo "
"; +echo abs(-5); + +echo "

"; + +/* Punto 2 */ + +echo ceil(4.3); +echo "
"; +echo ceil(9.999); +echo "
"; +echo ceil(-3.14); + +echo "

"; + +/* Punto 3 */ + +echo max(2, 3, 1, 6, 7); +echo "
"; +echo max(array(2, 4, 5)); + +echo "

"; + +/* Punto 4 */ + +echo min(2, 3, 1, 6, 7); +echo "
"; +echo min(array(2, 4, 5)); + +echo "

"; + +/* Punto 5 */ + +echo (rand(10,100)); + + ?> \ No newline at end of file diff --git a/strings.php b/strings.php index 15c5adc..fc7deb0 100644 --- a/strings.php +++ b/strings.php @@ -1,3 +1,73 @@
"; + +/* PUNTO 2 */ + +$a = "Hello World"; +print "$a"; +echo "

"; + +/* PUNTO 3 */ + +print "Id like to say $a"; +echo "

"; + +/* PUNTO 4 */ + +echo str_replace("World","Javier", $a); +echo "

"; + +/* PUNTO 5 */ + +$b = "HELLO WORLD"; + +echo str_ireplace("world","Javier", $b); +echo "

"; + +/* PUNTO 6 */ + +echo str_repeat($a, 5); +echo "

"; + +/* PUNTO 7 */ + +echo strlen($a); +echo "

"; + +/* PUNTO 8 */ + +$x = 'abcdef abcdef'; +$pos = strpos($x, 'a', 1); +echo $pos; +echo "

"; + +/* PUNTO 9 */ + +$c = "hello world"; +$c = ucfirst($c); +echo $c; +echo "

"; + +/* PUNTO 10 */ + +$d = "HELLO WORLD"; +$d = ucfirst($d); +$d = ucfirst(strtolower($d)); +echo $d; +echo "

"; + +/* PUNTO 11 */ + +$e = substr("Javier", -1); +echo "$e

"; +$f = substr("Javier", -2); +echo "$f

"; +$g = substr("Javier", -3, 1); +echo "$g"; + + ?> \ No newline at end of file diff --git a/types.php b/types.php index 15c5adc..a0f4a7e 100644 --- a/types.php +++ b/types.php @@ -1,3 +1,70 @@
"; + +/* integer */ + +$c = 5985; +var_dump($c); + +echo "

"; + +/* float */ + +$d = 10.365; +var_dump($d); + +echo "

"; + +/* String */ + +$f = "Hello world!"; +$g = 'Hello world!'; + +echo $f; +echo "
"; +echo $g; + +echo "

"; + +/* Array */ + +$cars = array("Volvo","BMW","Toyota"); +var_dump($cars); + +echo "

"; + +/* object */ + +class Pencil { + public $color; + public $model; + public function __construct($color, $model) { + $this->color = $color; + $this->model = $model; + } + public function message() { + return "My pencil is a " . $this->color . " " . $this->model . "!"; + } + } + + $myPencil = new Pencil("black", "Bic"); + echo $myPencil -> message(); + echo "
"; + $myPencil = new Pencil("red", "Pilot"); + echo $myPencil -> message(); + + echo "

"; + +/* null */ + +$h = "Hello world!"; +$i = null; +var_dump($i); + ?> \ No newline at end of file From eb833194784fc926b71a5a5936dd88be46be6be1 Mon Sep 17 00:00:00 2001 From: Javier-jpt <119037601+Javier-jpt@users.noreply.github.com> Date: Tue, 20 Dec 2022 12:37:46 +0100 Subject: [PATCH 6/7] Update README.md --- README.md | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7c787c3..d4c8b8c 100644 --- a/README.md +++ b/README.md @@ -6,40 +6,33 @@ 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 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. ## Index +- [Organization](#organitzation) - [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 -## Repository +## Organization -First of all you must fork this project into your GitHub account. +- In this project in the first instance I have created all the necessary files for its further development. Once finished, I modified the readme and made a "pull request" to upload the project with all the changes to Github. -To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. +## Requirements -Fork on GitHub +- Learn the basics to program in PHP. +- Understand what a server-side language is and what it is used for. +- Learn to use a LocalServer with XAMPP. ## 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 From d746b54194d41c1172e56c8a71ad47c94466f16d Mon Sep 17 00:00:00 2001 From: Javier Pascual Date: Tue, 20 Dec 2022 13:29:54 +0100 Subject: [PATCH 7/7] End exercise! --- arrays.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ functions.php | 45 +++++++++++++++++++++++++++++++++++++++++ phpinfo.php | 2 ++ types.php | 26 +++++++----------------- 4 files changed, 110 insertions(+), 19 deletions(-) diff --git a/arrays.php b/arrays.php index 15c5adc..2341d98 100644 --- a/arrays.php +++ b/arrays.php @@ -1,3 +1,59 @@
"; + +/* PUNTO 2 */ + +$b = ['1', '2', '3.55', '4', '5.12']; +var_dump(implode(", ", $b)); +echo "

"; + +/* PUNTO 3 */ + +$colors = array ( + array("Red",22,18), + array("Blue",15,13), + array("Green",5,2), + array("Black",17,15) + ); + +echo $colors[0][0].": In stock: ".$colors[0][1].", sold: ".$colors[0][2].".
"; +echo $colors[1][0].": In stock: ".$colors[1][1].", sold: ".$colors[1][2].".
"; +echo $colors[2][0].": In stock: ".$colors[2][1].", sold: ".$colors[2][2].".
"; +echo $colors[3][0].": In stock: ".$colors[3][1].", sold: ".$colors[3][2].".
"; +echo "

"; + +/* PUNTO 4 */ + +$a[0] = 1; +$a[1] = 3; +$a[2] = 5; +var_dump(count($a)); +echo "

"; + +/* PUNTO 5 */ + +$c = array('green', 'red', 'yellow'); +$d = array('avocado', 'apple', 'banana'); +$e = array_combine($c, $d); + +print_r($e); +echo "

"; + +/* PUNTO 6 */ + +$frutas = array('Manzana', 'Sandia', 'Melocoton'); +echo end($frutas); +echo "

"; + +/* PUNTO 7 */ + +$animals = array("Horse", "Cat"); +array_push($animals, "Dog", "Rat"); +print_r($animals); + ?> \ No newline at end of file diff --git a/functions.php b/functions.php index 15c5adc..47f0e8c 100644 --- a/functions.php +++ b/functions.php @@ -1,3 +1,48 @@
"; + +/* PUNTO 2 */ + +function mul($x, $y) { + return $x * $y; +} + +echo mul($x,$y); + +echo "

"; + +/* PUNTO 3 */ + +function div($x, $y) { + return $x / $y; +} + +echo div($x,$y); + +echo "

"; + +/* PUNTO 4 */ + +function operation($x, $y, $operation) { + if($operation == "add") { + return $x + $y; + } else if ($operation == "multiply") { + return$x * $y; + } +} + +echo operation(7, 6, "multiply"); + ?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php index 15c5adc..6480abf 100644 --- a/phpinfo.php +++ b/phpinfo.php @@ -1,3 +1,5 @@ \ No newline at end of file diff --git a/types.php b/types.php index a0f4a7e..f4a456d 100644 --- a/types.php +++ b/types.php @@ -41,25 +41,13 @@ /* object */ -class Pencil { - public $color; - public $model; - public function __construct($color, $model) { - $this->color = $color; - $this->model = $model; - } - public function message() { - return "My pencil is a " . $this->color . " " . $this->model . "!"; - } - } - - $myPencil = new Pencil("black", "Bic"); - echo $myPencil -> message(); - echo "
"; - $myPencil = new Pencil("red", "Pilot"); - echo $myPencil -> message(); - - echo "

"; +$object = (object) [ + 'propertyOne' => 'foo', + 'propertyTwo' => 42, +]; + +var_dump($object); +echo "

"; /* null */