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
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,20 @@

## Index <!-- omit in toc -->

- [Requirements](#requirements)
- [Repository](#repository)
- [How to run](#How-to-run)
- [Technologies used](#technologies-used)
- [Project delivery](#project-delivery)
- [Resources](#resources)

## Requirements
## How to run

- Learn the basics to program in PHP
- Understand what a server-side language is and what it is used for

## Repository

First of all you must fork this project into your GitHub account.

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.

<img src="https://docs.github.com/assets/cb-23088/images/help/repository/fork_button.png" alt="Fork on GitHub" width='450'>
- Install XAMPP
- Run Apache in the Xampp control panel
- The project will run on localhost:80 or http://127.0.0.1/

## 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"

## Resources

- [What can PHP do?](https://www.php.net/manual/es/intro-whatcando.php)
Expand Down
104 changes: 104 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
echo '<strong>results</strong><br><br>';
// array declarations

$fruits = ['orange', 'banana', 'apple'];

$nums = [1, 2.4, 5, 3, 4.6];

$multidimensionArr = ['hello', 'world', [1, 2, 3]];

// get length of array

function getLengthOfArray($arr)
{
return count($arr);
}

echo getLengthOfArray($multidimensionArr) . '<br>';

// combine arrays

function combineArrays($arr1, $arr2)
{
return array_merge($arr1, $arr2);
}

print_r(combineArrays($fruits, $nums));
echo '<br>';

// return last element

function returnLast($arr)
{
return $arr[count($arr) - 1];
}

print_r(returnLast($fruits));
echo '<br>';

// add element to array

function addElement($arr, $elementToAdd)
{
array_push($arr, $elementToAdd);
return $arr;
}

print_r(addElement($fruits, 'cherries'));
echo '<br>';



echo '<h1>Arrays</h1>
<pre>
// array declarations

$fruits = ["orange", "banana", "apple"];

$nums = [1, 2.4, 5, 3, 4.6];

$multidimensionArr = ["hello", "world", [1, 2, 3]];

// get length of array

function getLengthOfArray($arr)
{
return count($arr);
}

echo getLengthOfArray($multidimensionArr) . "<br>";

// combine arrays

function combineArrays($arr1, $arr2)
{
return array_merge($arr1, $arr2);
}

print_r(combineArrays($fruits, $nums));
echo "<br>";

// return last element

function returnLast($arr)
{
return $arr[count($arr) - 1];
}

print_r(returnLast($fruits));
echo "<br>";

// add element to array

function addElement($arr, $elementToAdd)
{
array_push($arr, $elementToAdd);
return $arr;
}

print_r(addElement($fruits, "cherries"));
echo "<br>";

</pre>
';
127 changes: 127 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
echo '<strong>results</strong><br><br>';
// set default timezone
date_default_timezone_set('Europe/Madrid');

$weekDay = date('w');
$month = date('F');
$minutes = date('i');

// check if today is monday

if ($weekDay == 1) {
echo 'Today is Monday <br>';
}

// check if month is october

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

//check minutes

if($minutes < 10){
echo "the current minute is less than 10 <br>";
} else if ($minutes > 15){
echo "the current minute is more than 15 <br>";
} else{
echo "does not meet any conditions <br>";
}

//display different message depending on what day today is

switch ($weekDay) {
case 1:
echo "Hey man, today is Monday <br>";
break;
case 2:
echo "Hey man, today is Tuesday <br>";
break;
case 3:
echo "Hey man, today is Wednesday <br>";
break;
case 4:
echo "Hey man, today is Thursday <br>";
break;
case 5:
echo "Hey man, today is Friday <br>";
break;
case 6:
echo "Hey man, today is Saturday <br>";
break;
case 0:
echo "Hey man, today is Sunday <br>";
break;

default:
echo "Never getting here...";
break;
}


echo '
<h1>Conditionals</h1>
<pre><br>
date_default_timezone_set("Europe/Madrid");<br>
<br>
$weekDay = date("w");<br>
$month = date("F");<br>
$minutes = date("i");<br>
<br>
// check if today is monday<br>
<br>
if ($weekDay == 1) {<br>
echo "Today is Monday <br>";<br>
}<br>
<br>
// check if month is october<br>
<br>
if ($month == "October") {<br>
echo "We are in " . $month ."<br>";<br>
} else {<br>
echo $month . "<br>";<br>
}<br>
<br>
//check minutes<br>
<br>
if($minutes < 10){<br>
echo "the current minute is less than 10 <br>";<br>
} else if ($minutes > 15){<br>
echo "the current minute is more than 15 <br>";<br>
} else{<br>
echo "does not meet any conditions <br>";<br>
}<br>
' . '<br>
//display different message depending on what day today is<br>
<br>
switch ($weekDay) {<br>
case 1:<br>
echo "Hey man, today is Monday <br>";<br>
break;<br>
case 2:<br>
echo "Hey man, today is Tuesday <br>";<br>
break;<br>
case 3:<br>
echo "Hey man, today is Wednesday <br>";<br>
break;<br>
case 4:<br>
echo "Hey man, today is Thursday <br>";<br>
break;<br>
case 5:<br>
echo "Hey man, today is Friday <br>";<br>
break;<br>
case 6:<br>
echo "Hey man, today is Saturday <br>";<br>
break;<br>
case 0:<br>
echo "Hey man, today is Sunday <br>";<br>
break;<br>
<br>
default:<br>
echo "Never getting here...";<br>
break;<br>
}</pre>';
?>
47 changes: 47 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
echo '<strong>results</strong><br><br>';
// instance DateTime

$date = new DateTime();

// different time formats

echo $date->format('Y-m-m');

echo "<br>";

date_default_timezone_set('Europe/Madrid');

echo $date->format('m/d/Y');

echo "<br>";

echo $date->format('m');

echo "<br>";

echo $date->format('i');

echo '<pre>
$date = new DateTime();

// different time formats

echo $date->format("Y-m-m");

echo "<br>";

date_default_timezone_set("Europe/Madrid");

echo $date->format("m/d/Y");

echo "<br>";

echo $date->format("m");

echo "<br>";

echo $date->format("i");
</pre>'

?>
Loading