diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..4e83d50 --- /dev/null +++ b/arrays.php @@ -0,0 +1,37 @@ +"; + +$arrayNumbers = array(1,2,4,5); +$arrayNumbers2 = array(5,2,2,2); +print_r($arrayNumbers); +echo "
"; + +$arrayMultidimentsional = array(1,array(9,8,7),4,5.3); +print_r($arrayMultidimentsional); +echo "
"; + +echo count($arrayMultidimentsional); +echo "
"; + +print_r(array_merge($arrayString,$arrayNumbers)); +echo "
"; +print_r(array_combine($arrayString,$arrayNumbers)); +echo "
"; +print_r(array_intersect($arrayNumbers2,$arrayNumbers)); +echo "
"; +print_r(array_diff($arrayNumbers2,$arrayNumbers)); +echo "
"; +// print_r(array_count_values($arrayNumbers2,$arrayNumbers)); +// echo "
"; + +print_r(end($arrayNumbers)); +echo "
"; + +array_push($arrayNumbers,8); +print_r($arrayNumbers); +echo "
"; + +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..e59b868 --- /dev/null +++ b/conditionals.php @@ -0,0 +1,44 @@ + format("M") == "Oct"){ + echo "We are in October"; +}else { + print $dateMonth -> format("M")."
"; +} + +$minute = date("i"); + +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"."
"; +} + +$dayWeek = date("w"); + +switch ($dayWeek) { + case 0: + echo "Monday"."
"; + break; + case 1: + echo "Tuesday"."
"; + break; + case 2: + echo "Wednesday"."
"; + break; + case 3: + echo "Thursday"."
"; + break; +} + +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..5a11ecb --- /dev/null +++ b/dates.php @@ -0,0 +1,9 @@ + format('Y-m-d')."
"; +echo $fecha -> format('d')."
"; +echo $fecha -> format('m')."
"; +echo $fecha -> format('i')."
"; + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..021c59c --- /dev/null +++ b/functions.php @@ -0,0 +1,50 @@ +"; + +function plus($arg_1,$arg_2){ + echo "Funcion de ejemplo"; + return print($arg_1 * $arg_2); + } + + plus(2,5) + echo "
"; + +function div($arg_1,$arg_2){ + echo "Funcion de ejemplo"; + return print($arg_1 / $arg_2); + } + + div(30,2); + echo "
"; + + +function multi($arg_1,$arg_2,$variable){ + switch ($variable) { + case 'suma': + suma($arg_1,$arg_2); + break; + case 'plus': + plus($arg_1,$arg_2); + break; + case 'div': + div($arg_1,$arg_2); + break; + } + return $arg_1 / $arg_2; + } + +multi (1,2,"suma"); +echo "
"; +multi (5,2,"plus"); +echo "
"; +multi (10,2,"div"); +echo "
"; + +?> \ No newline at end of file diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..62a2575 --- /dev/null +++ b/iterators.php @@ -0,0 +1,33 @@ +"; + +$numeros = array (1,2,3,4); + +foreach ($numeros as &$value) + + print "the number is: $value
"; + +$x=0; +while ($x < 10){ + print "the number is $x
"; + $x++; +} + +echo "
"; + +$y=10; +do{ + print "the number is $y
"; + $y--; +} +while($y > 0); + + +?> \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..667549a --- /dev/null +++ b/maths.php @@ -0,0 +1,9 @@ +"); +echo(ceil(6.3) . "
"); +echo(max(6.3,5,4,20) . "
"); +echo(min(6.3,5,4,20) . "
"); +echo(rand(2,20) . "
"); +$random = rand(10,100); +echo$random. "
"; +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..2f5e1ca --- /dev/null +++ b/operators.php @@ -0,0 +1,73 @@ +"; +echo $x - $y."
"; +echo $x * $y."
"; +echo $x / $y."
"; +echo $x % $y."
"; + +$a = 20; +$b = 21; + +if( $a == $b ) { + echo "a and b is equal
"; +}else { + echo "a is not equal to b
"; +} +if( $a === $b ) { + echo "a and b is equal
"; +}else { + echo "a is not equal to b
"; +} +if( $a != $b ) { + echo "a and b is diferent
"; +}else { + echo "a is equal to b
"; +} +if( $a < $b ) { + echo "a is smaller than b
"; + }else { + echo "b is smaller than a
"; + } +if( $a > $b ) { + echo "a is bigger than b
"; + }else { + echo "b is bigger than a
"; + } +if( $a <= $b ) { + echo "a is smaller or equal than b
"; + }else { + echo "b is smaller or equal than a
"; + } +if( $a >= $b ) { + echo "a is bigger or equal than b
"; + }else { + echo "b is bigger or equal than a
"; + } +if ($x == 10 and $y == 6) { + echo "Hello world!
"; +} +if ($x == 10 && $y == 6) { + echo "Hello world!
"; +} +if ($x == 10 || $y == 5) { + echo "Hello world!
"; +} +if ($x == 10 or $y == 5) { + echo "Hello world!
"; +} +if ($x == 10 && $y == 6) { + echo "Hello world! &&
"; +} +if (! ($x==9) ) { + echo "Hello world! water
"; +} +if ($x == 10 xor $y == 5) { + echo "Hello world! xor
"; +} + + +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..968c8df --- /dev/null +++ b/phpinfo.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..d049db3 --- /dev/null +++ b/print.php @@ -0,0 +1,45 @@ +"; // "\n" means line feed (avance de línea) + +echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', "\n", "
"; + +echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n" . "
"; // . is used to concatenate + +echo "Hello ", isset($name) ? $name : "Pau Tomás", "!" , "
"; + +$example = "The argument can be any expression"; +echo "$example which produces a string", "
"; + +$sports = ["tenis", "padel", "football", "basketball"]; +echo "My favourite sports are " . implode(", ", $sports) . "..." . "
"; // implode — Join array elements with a string + +echo 3 * 12; +echo "
"; + +//Instruction that makes ude of "print" + +print "This is a test with print.
"; + +$example = "The argument can be any expression"; +print "$example which produces a string
"; + +$sports = ["tenis", "padel", "football", "basketball"]; +print implode(", ", $sports); + +print "
"; +print 6 * 7; +print "
"; + + +//Instruction that makes use of "print_r" — Prints human-readable information about a variable + +echo "
";
+$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
+
+print_r ($a);
+echo "
"; + +?> \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..74a6591 --- /dev/null +++ b/strings.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..c7a3194 --- /dev/null +++ b/types.php @@ -0,0 +1,54 @@ +
'; + +// type integer +$b = 5985; +var_dump($b); +echo '

'; + +// type float +$c = 10.365; +var_dump($c); +echo '

'; + +// type boolean +$d = true; +var_dump($d); +echo '

'; + +// null +$e = null; +var_dump($e); + +// type array +$cars = array("Volvo", "BMW", "Toyota"); +var_dump($cars); +echo '

'; + +// type object (class) +class Car +{ + public $color; + public $model; + public function __construct($color, $model) + { + $this->color = $color; + $this->model = $model; + } + public function message() + { + return "My car is a " . $this->color . " " . $this->model . "!"; + } +} + +$myCar = new Car("black", "Volvo"); +echo $myCar->message(); +echo "
"; +$myCar = new Car("red", "Toyota"); +echo $myCar->message(); +echo '

'; + +?> \ No newline at end of file