Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 01.print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
echo "hola?";
print"hola2?";
$array = array('apple', 'banana', 'orange');

print_r($array);




?>
26 changes: 26 additions & 0 deletions 02.iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

for ($i = 1; $i <= 10; $i++) {
echo $i . "<br>";
}


foreach ($fruits as $fruit) {
echo $fruit . "<br>";
}

$i = 1;
while ($i <= 10) {
echo $i . "<br>";
$i++;
}


$i2 = 1;
do {
echo $i2 . "<br>";
$i2++;
} while ($i2 <= 10);


?>
26 changes: 26 additions & 0 deletions 03.operators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
var_dump(1 == 2);
$a = 5;
$b = 3;

echo $a + $b . "<br>"; // Outputs 8
echo $a - $b . "<br>"; // Outputs 2
echo $a * $b . "<br>"; // Outputs 15
echo $a / $b . "<br>"; // Outputs 1.6666666666667
echo $a % $b . "<br>"; // Outputs 2


echo $a == $b . "<br>"; // Outputs false
echo $a != $b . "<br>"; // Outputs true
echo $a < $b . "<br>"; // Outputs false
echo $a > $b . "<br>";


$c = true;
$d = false;

echo ($c && $d) . "<br>"; // Outputs false
echo ($c || $d) . "<br>"; // Outputs true
echo !$c . "<br>"; // Outputs false
echo ($c xor $d) . "<br>"; // Outputs true
?>
28 changes: 28 additions & 0 deletions 04.dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
$date1 = new DateTime();
echo $date1->format("Y-m-d");

$date2 = new DateTime("2022-12-20");
echo $date2->format("Y-m-d"); // Outputs "2022-12-20"

$timestamp = strtotime("2022-12-20");
$date3 = new DateTime("@$timestamp");
echo $date3->format("Y-m-d"); // Outputs "2022-12-20"

echo date("d"); // Outputs the current day of the month as a 2-digit number (e.g. "01", "02", ..., "31")

echo $date3->format("d"); // Outputs the current day of the month as a 2-digit number (e.g. "01", "02", ..., "31")

echo date("m"); // Outputs the current month as a 2-digit number (e.g. "01", "02", ..., "12")

$date5 = new DateTime();
echo $date5->format("m"); // Outputs the current month as a 2-digit number (e.g. "01", "02", ..., "12")

echo date("i"); // Outputs the current minute as a 2-digit number with leading zeros (e.g. "00", "01", ..., "59")

$date6 = new DateTime();
echo $date6->format("i"); // Outputs the current minute as a 2-digit number with leading zeros (e.g. "00", "01", ..., "59")



?>
83 changes: 83 additions & 0 deletions 05.conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

$day = date("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday")

if ($day == "Monday") {
echo "We are on Monday";
}

$date1 = new DateTime();
$day = $date1->format("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday")

if ($day == "Monday") {
echo "We are on Monday";
}


$month = date("F"); // Get the current month as a full textual representation (e.g. "January", "February", ..., "December")

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

$date2 = new DateTime();
$month = $date2->format("F"); // Get the current month as a full textual representation (e.g. "January", "February", ..., "December")

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

$minute = date("i"); // Get the current minute as a 2-digit number (e.g. "00", "01", ..., "59")

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";
}

$date3 = new DateTime();
$minute = $date3->format("i"); // Get the current minute as a 2-digit number (e.g. "00", "01", ..., "59")

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";
}


$day = date("l"); // Get the current day of the week as a full textual representation (e.g. "Monday", "Tuesday", ..., "Sunday")

switch ($day) {
case "Monday":
echo "It's the start of a new week!";
break;
case "Wednesday":
echo "Hump day!";
break;
case "Friday":
echo "TGIF!";
break;
case "Saturday":
echo "Time to relax and enjoy the weekend!";
break;
case "Sunday":
echo "End of the weekend, time to get ready for another week.";
break;
default:
echo "Just another day...";
break;
}





?>
28 changes: 28 additions & 0 deletions 06.types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
// Define a boolean variable
$bool = true;

// Define an integer variable
$int = 123;

// Define a float variable
$float = 3.14;

// Define a string variable
$string = "Hello, World!";

// Define an array variable
$array = array(1, 2, 3, 4, 5);

// Define an object variable
class MyClass { }
$object = new MyClass();

// Define a NULL variable
$null = null;





?>
20 changes: 20 additions & 0 deletions 07.maths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
// Define a variable with the result of the abs function (returns the absolute value)
$absValue = abs(-123); // $absValue will be 123

// Define a variable with the result of the ceil function (returns the next highest integer)
$roundedUp = ceil(3.14); // $roundedUp will be 4

// Define a variable with the result of the max function (returns the highest value of a series of values)
$maxValue = max(1, 2, 3, 4, 5); // $maxValue will be 5

// Define a variable with the result of the min function (returns the lowest value of a series of values)
$minValue = min(1, 2, 3, 4, 5); // $minValue will be 1

// Define a variable with the result of the rand function (returns a random number)
$randomNumber = rand(1, 100); // $randomNumber will be a random number between 1 and 100 (inclusive)




?>
48 changes: 48 additions & 0 deletions 08.strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
// Print a text string
echo "Hello, World!";

// Print a text string that interprets variables
$name = "John";
echo "Hello, $name!";

// Concatenate a previously declared variable in a text string
$name = "John";
echo "Hello, " . $name . "!";

// Execute the function that allows you to replace text in a string (case sensitive)
$text = "Hello, World!";
$newText = str_replace("World", "PHP", $text);
echo $newText; // Outputs "Hello, PHP!"

// Execute the function that allows you to replace text in a string (without taking into account upper / lower case)
$text = "Hello, World!";
$newText = str_ireplace("world", "PHP", $text);
echo $newText; // Outputs "Hello, PHP!"

// Execute the function that allows you to write a text N times
$text = "Hello, World! ";
echo str_repeat($text, 3); // Outputs "Hello, World! Hello, World! Hello, World! "

// Execute the function that allows to obtain the length of a text string
$text = "Hello, World!";
echo strlen($text); // Outputs 13

// Executes the function that allows to obtain the position of the first occurrence of a text within a text string
$text = "Hello, World!";
echo strpos($text, "W"); // Outputs 6

// Execute the function that allows a text string to be capitalized
$text = "hello, world!";
echo ucwords($text); // Outputs "Hello, World!"

// Execute the function that allows you to transform a text string to lowercase
$text = "HELLO, WORLD!";
echo strtolower($text); // Outputs "hello, world!"

// Execute the function that allows to obtain a text substring from a given position
$text = "Hello, World!";
echo substr($text, 6);


?>
32 changes: 32 additions & 0 deletions 09.arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// Define a simple array composed of text strings
$array1 = array("apple", "banana", "orange");

// Define a simple array consisting of whole numbers and decimal numbers
$array2 = array(1, 2.5, 3, 4.5);

// Define a multidimensional array
$array3 = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);

// Execute the function that allows to obtain the length of an array
echo count($array1); // Outputs 3

// Execute the function that allows to obtain the combination of two arrays
$combinedArray = array_merge($array1, $array2);
print_r($combinedArray);
// Outputs Array ( [0] => apple [1] => banana [2] => orange [3] => 1 [4] => 2.5 [5] => 3 [6] => 4.5 )

// Execute the function that once is given an array return the last element of it
echo end($array1); // Outputs "orange"

// Execute the function that once is given an array add a new element to the array in question
array_push($array1, "mango");
print_r($array1); // Outputs Array ( [0] => apple [1] => banana [2] => orange [3] => mango )



?>
38 changes: 38 additions & 0 deletions 10.functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
// Create a function that given two numbers returns the sum of both
function sum($x, $y) {
return $x + $y;
}

// Create a function that given two numbers returns the multiplication of both
function multiply($x, $y) {
return $x * $y;
}

// Create a function that given two numbers returns the division of both
function divide($x, $y) {
return $x / $y;
}

// Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation
function calculate($x, $y, $operation) {
switch ($operation) {
case "add":
return sum($x, $y);
case "multiply":
return multiply($x, $y);
case "divide":
return divide($x, $y);
default:
return "Invalid operation";
}
}

// Test the calculate function
echo calculate(1, 2, "add"); // Outputs 3
echo calculate(3, 4, "multiply"); // Outputs 12
echo calculate(6, 2, "divide"); // Outputs 3
echo calculate(5, 6, "subtract"); // Outputs "Invalid operation"


?>
5 changes: 5 additions & 0 deletions 11.phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php



?>