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

#Define a simple array composed of text strings

$pokemon = array("Pikachu", "Charmander", "Mew");

echo "I like " . $pokemon[0];

echo "<br>";

#Define a simple array consisting of whole numbers and decimal numbers


$numbers = array(1, 2.4, 4, 6, 7.9);

echo "I have " . $numbers[0];

echo "<br>";

#Define a multidimensional array

$brand = array (
array("Sony","Nike"),
array("Microsoft","Adidas"),
array("Nintendo","Kinder"),
);

echo $brand[0][1];

echo "<br>";

#Execute the function that allows to obtain the length of an array


$game = array(1, 2, 3, 4, 5, 6, 7);

echo sizeof($game);

echo"<br>";

#Execute the function that allows to obtain the combination of two arrays


$days = array("Monday","Sunday","Friday");
$months = array("January","May","December");

$year = array_combine($days,$months);
print_r($year);

echo "<br>";

#Execute the function that once is given an array return the last element of it


$last = array("one", "two", "three", "four");

echo end($last);

echo "<br>";

#Execute the function that once is given an array add a new element to the array in question

$colors = array("blue","purple");
array_push($colors,"black","yellow","orange","green");
print_r($colors);

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

#Create a simple condition that evaluates whether the current day is Monday.

$currentDay = date('l');
$currentMonth = date('m');

if (date('l') === 'Monday') {
echo "We are on Monday";
}else{echo "Today is&nbsp". date("l");
}

echo "<br>";

#Create a simple condition that evaluates whether the current month is October.

if (date('m') === "October"){
echo "We are in October";
}else{
echo "Today is&nbsp". date('F');
}

echo "<br>";

#Create a double condition

$currentMinute = date('i');

if($currentMinute < 10){
echo "The current minute is less than 10";
}else if($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.

$day = date('D');

switch($day){
case 'Sun';
echo "Today is Sunday";
break;
case 'Sat';
echo "Today is Saturday";
break;
case 'Fri';
echo "Today is Friday";
break;
case 'Thu';
echo "Today is Thursday";
break;
case 'Wed';
echo "Today is Wednesday";
break;
case 'Tue';
echo "Today is Tuesday";
break;
case 'Mon';
echo "Today is Monday";
break;
}
?>
33 changes: 33 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

$dates = date("y-m-d");

echo $dates;

echo "<br>";

$dates = date("D-M-Y");

echo $dates;

echo"<br>";

$dates = date("D");

echo $dates;

echo "<br>";

$dates = date("m");

echo $dates;

echo "<br>";

$dates = date("i");

echo $dates;



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

#Create a function that given two numbers returns the sum of both

function sum(int $x, int $y)
{
return $x + $y;
}

echo sum(10, 25);

echo "<br>";

#Create a function that given two numbers returns the multiplication of both

function multiply(int $a, int $b) {

return $a * $b;
}

echo multiply(10, 10);

echo "<br>";

#reate a function that given two numbers returns the division of both

function division(int $c, int $d) {

return $c / $d;
}
echo division(20, 5);

echo "<br>";

#Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.

function operation ($f, $g, $operation){
if($operation == "multiply"){
return $f * $g;
}
}

echo operation(3, 5, "multiply");

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

#Generate a snippet that makes use of for

for($i=0; $i < 10; $i++){
echo $i;
}

echo "<br>";

#Generate a snippet that makes use of foreach

$drinks = array("cocacola", "fanta", "pepsi", "appletiser");

foreach($drinks as $choose){
echo $choose;
}

echo "<br>";

#Generate a snippet that uses while

$more = 10;

while($more < 20){
echo $more;
$more++;
}

echo "<br>";

#Generate a snippet that uses do while

$less = 20;

do{
echo $less;
$less++;
}
while($less < 25);


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

#Define a variable whose value is the result of the function that returns an absolute value.


$abs = abs(2.4);

echo $abs;

echo "<br>";

#Define a variable whose value is the result of the function that returns a rounded value to the next highest integer.

$round = round(3.6);

echo $round;

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

echo"<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(5, 4, 1, 6, 9);

echo $lowest;

echo "<br>";

#Define a variable whose value is the result of the function that returns a random number

$random = rand();

echo $random;

echo"<br>";

?>
Loading