Skip to content

Solution: Isaura Martí Teixidó #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
58 changes: 12 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,17 @@
`#php` `#basics` `#master-in-software-development`

# PHP Basics <!-- omit in toc -->

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
</p>

> In this project you will learn the basic notions of the famous PHP language which is so used in the world of web development.
>
> What distinguishes PHP from other languages ​​such as Javascript is that the code is executed on the server, generating HTML and sending it to the client.
It is a library with different features that php offers.

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

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

## Requirements

- 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'>

## 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)
- [Sample guide for README](https://gist.github.com/Villanuevand/6386899f70346d4580c723232524d35a)
- [XAMPP](https://www.apachefriends.org/es/index.html)
- [How to install XAMPP on Windows](https://www.youtube.com/watch?v=h6DEDm7C37A)
- [What is a web server?](https://www.youtube.com/watch?v=Yt1nesKi5Ec)
- [Web server basics](https://www.youtube.com/watch?v=3VqfpVKvlxQ)
- [Print](#print)
- [Iterators](#iterators)
- [Operators](#operators)
- [Dates](#dates)
- [Conditionals](#conditionals)
- [Types](#types)
- [Maths](#maths)
- [Strings](#strings)
- [Arrays](#arrays)
- [Functions](#functions)
- [Phpinfo](#phpinfo)
116 changes: 116 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<style>
body {
font-family: Georgia, 'Times New Roman', Times, serif;
padding: 2em;
}

h2 {
margin-top: 2em;
color: #18978F;
}

h4 {
font-weight: bold;
font-size: 16;
font-family: Georgia, 'Times New Roman', Times, serif;
}
</style>

<?php

echo "<h2>Types</h2>";

echo '<pre>
<h4>
$arrStr = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");

$arrNum = [1, 4, 6, 1.4, 5.9, 5, 7];

$arrMult = [1, 4, 6, [4, 9, 4]];
</h4>
</pre>';
$arrStr = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$arrNum = [1, 4, 6, 1.4, 5.9, 5, 7];
$arrMult = [1, 4, 6, [4, 9, 4]];

echo "<h2>Length</h2>";

echo '<pre><h4>
function lengthArr($arr)
{
return count($arr);
}

$resultLengthA = lengthArr($arrStr);
</h4></pre>';

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

$resultLengthA = lengthArr($arrStr);

echo $resultLengthA;

echo "<h2>Combination Two Arrays</h2>";

echo '<pre><h4>
function combination($arr1, $arr2)
{
return array_combine($arr1, $arr2);
}

$resultCombination = combination($arrNum, $arrStr);
</h4></pre>';

function combination($arr1, $arr2)
{
return array_combine($arr1, $arr2);
}

$resultCombination = combination($arrNum, $arrStr);

print_r($resultCombination);

echo "<h2>Last Element</h2>";

echo '<pre><h4>
function lastEl($arr)
{
return end($arr);
}

$resultLastEl = lastEl($arrNum);
</h4></pre>';

function lastEl($arr)
{
return end($arr);
}

$resultLastEl = lastEl($arrNum);

echo $resultLastEl;

echo "<h2>Add Element</h2>";

echo '<pre><h4>
function addElement($arr, $elAdd)
{
return array_push($arr, $elAdd);
return $arr;
}

$resultAddEl = addElement($arrStr, "Monday");
</h4></pre>';

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

$resultAddEl = addElement($arrStr, "Monday");

print_r($resultAddEl);
131 changes: 131 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<style>
body {
font-family: Georgia, 'Times New Roman', Times, serif;
padding: 2em;
}

h2 {
color: #18978F;
}

h4 {
font-weight: bold;
font-size: 16;
font-family: Georgia, 'Times New Roman', Times, serif;
}
</style>

<?php

echo "<h4>&dollar;currentDay = new DateTime();</h4>";

$currentDay = new DateTime();


echo "<h2>Current day = Monday</h2>";

echo "<h4>&dollar;day = &dollar;currentDay -> format('D');</h4>";
$day = $currentDay->format('D');

echo '<pre><h4>
if ($day == "Mon") {
echo "We are on Monday";
}
</h4></pre>';

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

echo "<h2>Current month = October</h2>";

echo "<h4>&dollar;month = &dollar;currentDay -> format('M');</h4>";
$month = $currentDay->format('m');

echo '<pre><h4>
if ($month == 10) {
echo "We are in October";
}
</h4></pre>';

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

echo "<h2>Double condition</h2>";

echo "<h4>&dollar;currentMinute = &dollar;currentDay -> format('i');</h4>";
$currentMinute = $currentDay->format('i');

echo '<pre><h4>
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";
}
</h4></pre>';

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 "<h2>Switch</h2>";

echo "<h4>&dollar;dayOfWeek = &dollar;currentDay -> format('D');</h4>";
$dayOfWeek = $currentDay->format('D');

echo '<pre><h4>
switch ($dayOfWeek) {
case "Mon":
echo "Today is Monday";
break;
case "Tue":
echo "Today is Tuesday";
break;
case "Wed":
echo "Today is Wednesday";
break;
case "Thu":
echo "Today is Thursday";
break;
case "Fri":
echo "Today is Friday";
break;
case "Sat":
echo "Today is Saturday";
break;
default:
echo "Today is Sunday";
}

</h4></pre>';

switch ($dayOfWeek) {
case "Mon":
echo "Today is Monday";
break;
case "Tue":
echo "Today is Tuesday";
break;
case "Wed":
echo "Today is Wednesday";
break;
case "Thu":
echo "Today is Thursday";
break;
case "Fri":
echo "Today is Friday";
break;
case "Sat":
echo "Today is Saturday";
break;
default:
echo "Today is Sunday";
}
53 changes: 53 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<style>
body {
font-family: Georgia, 'Times New Roman', Times, serif;
padding: 2em;
}

h2 {
color: #18978F;
}

h3 {
color: #DF7861;
}
</style>
<?php

echo "<h4>&dollar;today = new DateTime();</h4>";

$today = new DateTime();

echo "<h2>Format 'Y-m-d'</h2>";
echo "<h4>echo &dollar;today -> format('Y-m-d');</h4>";

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

echo "<h2>Current date any format</h2>";
echo "<h3>(d-m-y)</h3>";

echo $today->format('d-m-y');

echo "<h3>(d-m-Y)</h3>";

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

echo "<h3>(d-M-Y)</h3>";

echo $today->format('d-M-Y');

echo "<h3>(D-m-Y)</h3>";

echo $today->format('D-m-Y');

echo "<h2>Current day</h2>";
echo "<h4>echo &dollar;today -> format('d'), &dollar;today -> format('D');</h4>";
echo $today->format('d'), $today->format('D');

echo "<h2>Current month</h2>";
echo "<h4>echo &dollar;today -> format('m');</h4>";
echo $today->format('m');

echo "<h2>Current minute</h2>";
echo "<h4>echo &dollar;today -> format('i');</h4>";
echo $today->format('i');
Loading