Skip to content
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

Solution: Ruben Zafra Traver #70

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
`#php` `#basics` `#master-in-software-development`
# PHP Basics 💻<!-- omit in toc -->

# 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.
> In this project we learnt the basic notions of PHP which is widely 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.

## 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
- Installing and using XAMPP
- Navigate to htdocs and create all files to appear on localserver
- 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.
## Screen Captures of Xampp

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.
<h2>Welcome Page XAMPP</h2>
<p>
<img src="img/xampp1.jpeg" alt="xampp1">
</p>

<img src="https://docs.github.com/assets/cb-23088/images/help/repository/fork_button.png" alt="Fork on GitHub" width='450'>
<h2>XAMPP Apache</h2>
<p>
<img src="img/xampp2.jpeg" alt="xampp2">
</p>

## 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"
\* Xampp
\* VSCode

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

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

echo "Regular array with strings: <br>";
$arrayStrings = array("apple", "pear", "banana");
print_r($arrayStrings);
echo "<br><br>";

echo "Regular array with numbers: <br>";
$arrayNums = array(1, 2, 4.1231);
print_r($arrayNums);
echo "<br><br>";

echo "Multidimensional array: <br>";
$arrayMultiDim = array(array("Volvo", 1), array("Seat", 2), array("Porsche", 0));
print_r($arrayMultiDim);
echo "<br><br>";

echo "Length of array: <br>";
echo count($arrayStrings);
echo "<br><br>";

echo "Combination of two arrays: <br>";
print_r(array_merge($arrayStrings, $arrayNums));
echo "<br><br>";

echo "Return last element of array: <br>";
echo (end($arrayNums)) . "<br><br>";

echo "Add element to array (2, 4): <br>";
array_push($arrayStrings, 2, 4);
print_r($arrayStrings);
?>
73 changes: 73 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

#Simple condition

$day = "Monday";

echo "'day' variable is: $day <br><br>";

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

echo "<br><br><br>";

#Simple condition with Date

$month = date("F");

echo "Month is date('F'): $month<br><br>";

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

#Double conditions

$minute = date("i");

echo "Minute is: $minute<br><br>";

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

echo "<br><br>";

#Switch statement

$dayOfTheWeek = date("l");

echo "The day of the week is: $dayOfTheWeek <br><br>";

switch ($dayOfTheWeek){
case "Monday":
echo "I eat potatoes<br><br>";
break;
case "Tuesday":
echo "I play the guitar<br><br>";
break;
case "Wednesday":
echo "I eat a lot of cheese :)<br><br>";
break;
case "Thursday":
echo "My cat destroys the Christmas Tree<br><br>";
break;
case "Friday":
echo "Hola Wilson<br><br>";
break;
case "Saturday":
echo "My name is Jeff<br>";
break;
case "Sunday":
echo "Paella para todos<br><br>";
break;
}

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

#Date time argument "Y-m-d"

echo "Date with argument 'Y-m-d': <br><br>";

echo "Today is " . date("Y-m-d");

echo "<br><br><br>";

#Date time argument "Y-m-d"

echo "Date with any format 'Y/m/d/l': <br><br>";

echo "Today is " . date("Y/m/d/l");

echo "<br><br><br>";

#Get Current Day

echo "Current day 'l': <br><br>";

echo "Today is " . date("l");

echo "<br><br><br>";

#Get Current Month in numerical Format

echo "Current Month in numerical Format 'm': <br><br>";

echo "Today is " . date("m");

echo "<br><br><br>";

#Get current minutes with Leading zeros

echo "Current Minutes with leading zeros 'i': <br><br>";

echo "Current minute: " . date("i");

echo "<br><br><br>";

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

echo "Function that returns the sum of 2 values (1, 2): <br>";

function sum ($x, $y){
return $x + $y;
}
echo (sum(1, 2));

echo "<br><br>";

echo "Function that returns the multiplication of 2 values (3, 5): <br>";

function mul ($x, $y){
return $x * $y;
}
echo mul(3, 5);

echo "<br><br>";

echo "Function that returns the division of 2 values (15, 5): <br>";

function div ($x, $y){
return $x / $y;
}
echo div(15, 5);

echo "<br><br>";

echo "Function that returns the operation of 2 values depending on operation input ('add', 'multiply') (3, 5): <br>";

function operation ($x, $y, $operation){
if ($operation == "add"){
return $x + $y;
} else if($operation == "multiply"){
return $x * $y;
}
}
echo operation(3, 5, "add");
echo "<br>";
echo operation(3, 5, "multiply");

echo "<br><br>";

?>
Binary file added img/xampp1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/xampp2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

#for Loop

echo "- for Loop in PHP: <br><br>";

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

#forEach Loop

echo "- foreach Loop in PHP: <br><br>";

$fruits = array("Apple", "Orange", "Banana", "Kiwi");

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

echo "<br><br>";

#while Loop

echo "- while Loop in PHP: <br><br>";

$j = 0;

while ($j < 10) {
echo $j;
$j++;
}

echo "<br><br><br>";

#do while Loop

echo "- do while Loop in PHP: <br><br>";

$k = 0;

do {
echo $k;
$k++;
} while ($k < 10);

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

#Absolute Function

echo "This is the absolute function: <br><br>";

$absNum = -4.5;
echo "Number: $absNum<br>";

var_dump(abs($absNum));

echo "<br><br><br>";

#Rounded Function

echo "This is the rounded function: <br><br>";

$roundedNum = 4.52343;
echo "Number to round: $roundedNum<br>";

var_dump(round($roundedNum));

echo "<br><br><br>";

#Highest Value Function
echo "This is the highest value function: <br><br>";

$array = array(4, 5, 12, 23, 2, 1);
echo "Array to do highest value: <br>";
print_r($array);
echo "<br><br>";

echo "Max function: ";
echo max($array);

echo "<br><br><br>";

echo "Min function: ";
echo min($array);

echo "<br><br><br>";

echo "This is the random value function: <br><br>";

$random = rand();
echo "$random";

?>
Loading