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
36 changes: 36 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

//Define a simple array composed of text strings
$cars = [ "Ford", "Tesla", "Toyota", "Kia"];

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

//Define a multidimensional array
$motorcycles = array (
array("Yamaha ",22,18),
array("Benelli",15,13),
array("Kawasaki",5,2),
array("KTM",17,15)
);
echo $motorcycles[0][0]."<br>";

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

//Execute the function that allows to obtain the combination of two arrays
$colors1 = array('green', 'red', ' yellow');
$colors = array('green', 'red', ' yellow');
$c = array_combine($colors1, $colors);


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

//Execute the function that once is given an array add a new element to the array in question
$phones = array("apple", "samsung");
array_push($phones, "huawei", "xiaomi");
print_r($phones);


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

/* Create a simple condition that evaluates whether the current day is Monday. Only in the case that the condition is met, it shows a message of “We are on Monday”. */

$day = date('1');
if( $day =='Monday'){
echo 'We are on Monday';
}
//Create a simple condition that evaluates whether the current month is October,
// If the condition is met, it shows a message of the type "We are in October",
// Otherwise, if this condition is not met, show the current month in words as it come from DateTime.

$month= date('F');
if($month== 'October'){
echo "We are in October";
}else{
echo "We are in $month";
}
echo "<br>";
//Create a double condition that evaluates: if the current minute is less than 10,
//Displays a message of type "the current minute is less than 10", if the current minute is greater than 15,
// displays a message of the type "the current minute is more than 15",
// If you do not meet any of the two conditions above: Displays a message of the type
// "does not meet any conditions”

$currentMinute = date("i");
if ($currentMinute < 10) {
echo " the current minute is less than 10";
} elseif ($currentMinute > 15) {
echo " the current minute is more than 15";
} else {
echo " does not meet any conditions";
}

echo "<br>";

//Create a switch type control structure to display a different message depending on the current day of the
// week. You can write any type of message because the important thing is that you understand how it works
// and in what cases you can use it.

$day = date('l');
switch ($day) {
case 'Monday':
echo " $day";
break;
case 'Tuesday':
echo " $day";
break;
case 'Wednesday':
echo " $day";
break;
case 'Thursday':
echo " $day";
break;
case 'Friday':
echo " $day";
break;
case 'Saturday':
echo " $day";
break;
case 'Sunday':
echo " $day";
break;
}
?>
10 changes: 10 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$date = new DateTime();
echo date( format:"y-m-d" );
echo "<br>";
echo date( format: "D" );
echo "<br>";
echo date( format: "m");
echo "<br>";
echo date( 'i' );
?>
43 changes: 43 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

//Create a function that given two numbers returns the sum of both
function sum($a, $b) {
return $a + $b;
}
echo sum(2, 3);

//Create a function that given two numbers returns the multiplication of both
function multiplication($a, $b) {
return $a * $b;
}
echo multiplication(2, 3);

//Create a function that given two numbers returns the division of both
function division($a, $b) {
return $a / $b;
}
echo division(2, 3);

//Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation,
//Depending on the type of operation received by parameter, the function will execute the function responsible for performing the operation,
// since you have previously implemented the function for each operation separately.

function operation ($operation) {
switch ( $operation) {
case "add":
echo sum(2, 3);

break;
case "multiply":
echo multiplication(2, 3);
break;
case "divide":
echo division(2, 3);
break;
default:
return "You need to specify if you want to add, multiply or divide";
};
}
echo operation("divide");

?>
26 changes: 26 additions & 0 deletions 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>";
}

$array = ["a", "bb", "ccc"];
forEach($array as $value){
print "<p>$value</p>\n";
}

$a= 5;
while($a<=20):
echo $a."<br>";
$a++;
endwhile;

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


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

//Define a variable whose value is the result of the function that returns an absolute value.
$absolute= abs(-4.2);
echo $absolute."<br>";

//Define a variable whose value is the result of the function that returns a rounded value to the next highest integer.
$rounded=round(3.4);
echo $rounded."<br>";

//Define a variable whose value is the result of the function that returns the highest value of a series of values ​​that are received by parameter
$highest=max([2,3,1,6,7]);
echo $highest."<br>";

//Define a variable whose value is the result of the function that returns the lowest value of a series of values ​​that are received by parameter.
$lowest = min([2,3,1,6,7]);
echo $lowest."<br>";

//Define a variable whose value is the result of the function that returns a random number
$random = rand(10,100);
echo $random

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

$a= 2;
$b= 2.5;

var_dump($a*$b);

echo '<br>';

var_dump($a===$b);
echo '<br>';
$c=2;

var_dump($a && $c ===! 2)




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

phpinfo();

?>
23 changes: 23 additions & 0 deletions print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
function welcome() {
echo "<h1>Welcome Php</h1>";
}
welcome();

print "<h2>Print imprime solo una cadena de texto</h2>";

$arr= [1,2,3,4,5];
print_r ($arr)












?>
44 changes: 44 additions & 0 deletions strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
//Print a text string"
print "Merry christmas everyone <br>";

//Print a text string that interpret variables
$hi= "Hello";
$bye= "Good bye";
echo $hi."<br>";

//Concatenate a previously declared variable in a text string
echo $hi ."Mi nombre es Sofia <br>";

//Execute the function that allows you to replace text in a string
$replace = str_replace("Php", $hi, $bye);
echo $replace;

//Execute the function that allows you to replace text in a string (without taking into account upper / lower case)
$replaceNoSensitive = str_ireplace("php", $hi, $bye);
echo $replaceNoSensitive."<br>";

//Execute the function that allows you to write a text N times
echo str_repeat(" Argentina Campeón Mundial ", 10)."<br>";

//Execute the function that allows to obtain the length of a text string
$str = 'Happy New Year';
echo strlen($str)."<br>";


//Executes the function that allows to obtain the position of the first occurrence of a text within a text string
echo strpos("I love Messi so much","Messi")."<br>";

//Execute the function that allows a text string to be capitalized
$upper = $bye." in upper";
echo strtoupper($upper)."<br>";

//Execute the function that allows you to transform a text string to lowercase
$lower = " My name is Sofi ";
$lower = strtolower($lower);
echo $lower."<br>";

//Execute the function that allows to obtain a text substring from the position
echo substr('sofia', 3, -1);

?>
19 changes: 19 additions & 0 deletions types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
//Define a new variable and assign a value to each of the following types:
//boolean
//integer
//float
//string
//array
//object
//NULL

$variableBool= true;
$variableInteger= 6;
$variableFloat= 2.5;
$variableString= "Hello";
$variableArray= array(1,2,3,4,5);
$variableObj= (object) array('key' => 'value');
$variableNull= null;

?>