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
65 changes: 31 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
`#php` `#basics` `#master-in-software-development`
# PHP practice with the Assembler school

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

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

> 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.
These instructions will allow you to get a working copy of the project on your premises for development and testing purposes.

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

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

## Requirements
### Prerequirements 📋

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

## 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.
### Installing 🔧

<img src="https://docs.github.com/assets/cb-23088/images/help/repository/fork_button.png" alt="Fork on GitHub" width='450'>
- [Guide to install XAMPP](https://www.php.net/manual/es/intro-whatcando.php)

## Technologies used
When you have installed XAMPP follow the steps below.
1 - clone repository.
2 - save the repository in the folder on drive C: > xampp > htdocs.

\* 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"
## Running the tests ⚙️

To view the file, type the following in your browser:
#### localhost/folder-name




## Built With 🛠️


* [PHP](https://www.php.net/)




## Authors ✒️

* **Jose Torres** - [88jose](https://github.com/88jose)



## 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)
59 changes: 59 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Arrays</title>
</head>
<body>
<h1>Arrays.php</h1>
<?php
echo '<b>Create a simple string array</b><br><code>$string = ["Juan", "Pepe", "Mario"]</code><br>';
$string = ['Juan', 'Pepe', 'Mario'];
echo '<pre>';
var_dump($string);
echo '</pre>';

echo '<b>Create a simple numbers array</b><br><code>$numbers = [5, 8.1, 258, 35.9]</code><br>';
$numbers = [5, 8.1, 258, 35.9];
echo '<pre>';
var_dump($numbers);
echo '</pre>';

echo '<b>Create a nested array</b><br><code>$nested = [[5, 8.1, 258, 35.9],["Juan", "Pepe", "Mario"]]</code><br>';
$nested = [[5, 8.1, 258, 35.9],['Juan', 'Pepe', 'Mario']];
echo '<pre>';
var_dump($nested);
echo '</pre>';

echo '<b>Create a nested array</b><br>';
echo '<b style="color:red;"> Array length: ' . count($string) . '</b><br><code>count($string)</code>';
echo '<pre>';
var_dump($string);
echo '</pre>';

echo '<b>Combine arrays</b><br><code>$result = array_merge($numbers, $nested)</code>';
$result = array_merge($numbers, $nested);
echo '<pre>';
var_dump($result);
echo '</pre>';

echo '<b>Get last position of an array</b><br><code>end($string)</code><br>';
echo '<b style="color:red;"> Last position: ' . end($string) . '</b>';
echo '<pre>';
var_dump($string);
echo '</pre>';

echo '<b>Add elements to array</b><br><code>array_push($string, "Carlos", "Julio")</code><br>';
echo '<b> Added Carlos and Julio</b>';
array_push($string, 'Carlos', 'Julio');
echo '<pre>';
var_dump($string);
echo '</pre>';



?>
</body>
</html>
72 changes: 72 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Conditionals</title>
</head>
<body>
<h1>Iterators.php</h1>
<?php
$fecha = new DateTime();

echo '<p><b>Today is Monday?</b></p>';
if($fecha->format('w') === 1){
echo "We are on Monday";
}else{
echo "Today is not Monday";
}

echo '<p><b>Are we in October?</b></p>';
if($fecha->format('M') === 'Oct'){
echo "We are in October";
}else{
echo "We are not October";
}

echo '<p><b>Is the current minute less than 10?</b></p>';
if($fecha->format('i') < 10){
echo "The current minute is less than 10";
}else if($fecha->format('i') > 15){
echo "The current minute is more than 15";
}else{
echo "Does not meet any conditions";
}


echo '<p><b>What weekday is today?</b></p>';
switch($fecha->format('l')){
case 'Sunday':
echo "Today is Sunday";
break;

case 'Monday':
echo "Today is Monday";
break;

case 'Tuesday':
echo "Today is Tuesday";
break;

case 'Wenesday':
echo "Today is Wenesday";
break;

case 'Thursday':
echo "Today is Thursday";
break;

case 'Friday':
echo "Today is Friday";
break;

case 'Friday':
echo "Today is Friday";
break;

default: "There are no more days of the week";
}
?>
</body>
</html>
25 changes: 25 additions & 0 deletions date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Date</title>
</head>
<body>
<h1>Date.php</h1>
<?php
$fecha = new DateTime(null, new DateTimeZone('Europe/Madrid'));
echo '<p><b>Current date Europe/Madrid: </b></p>';
echo '<pre>';
var_dump($fecha);
echo '</pre><hr>';
echo '<p><b>Current date: </b>'. $fecha->format('Y-m-d') . '</p>';
echo '<p><b>Current day: </b>' . $fecha->format('d') . '</p>';
echo '<p><b>Current month: </b>' . $fecha->format('m') . '</p>';
echo '<p><b>Current minuts: </b>'. $fecha->format('00:i') . '</p>';

?>

</body>
</html>
49 changes: 49 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Functions</title>
</head>
<body>
<h1>Functions.php</h1>

<?php
echo '<b>Function add</b> <br>';
function add($num1, $num2){
return $num1 + $num2;
}
echo add(20, 30) . '<br>';

echo '<b>Function multiply</b> <br>';
function multiply($num1, $num2){
return $num1 * $num2;
}
echo multiply(20, 30) . '<br>';

echo '<b>Function division</b> <br>';
function division($num1, $num2){
echo $num1 / $num2;
}
division(50, 30) . '<br><br>';

echo '<br><br>';
echo '<b>Function operation</b> <br>';
function operation($num1, $operator, $num2){
if($operator === '+'){
echo 'Add: ' . $num1 + $num2 . '<br>';
}else if($operator === '*'){
echo 'Multilply: ' . $num1 * $num2 . '<br>';
}else if($operator === '/'){
echo 'Division: ' . $num1 / $num2 . '<br>';
}else{
echo "Error";
}
}
operation(70, '+' , 20) . '<br>';
operation(11, '*' , 4) . '<br>';
operation(65, '/' , 20) . '<br>';
?>
</body>
</html>
52 changes: 52 additions & 0 deletions iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Iterators</title>
</head>
<body>
<h1>Iterators.php</h1>
<?php
$names = array('Juan', 'Pedro', 'Roberto', 'Carlos');
$numbers = array(1, 2, 3, 4, 5, 6);
$num1 = 1;
$count = 0;

echo '<p>1- Iterating with<b> the for loop </b>through an array of strings</p>
<ul>';
for($i = 0; $i < count($names); $i++){
echo '<li>'. $names[$i] .'</li>';
}
echo '</ul>';

echo '<p>2- Iterating with<b> the foreach loop </b>through an array of strings</p>
<ul>';
foreach($names as $name){
echo '<li>'. $name .'</li>';
}
echo '</ul>';

echo '<p>3- Iterating with<b> the while loop </b>through an array of numbers</p>
<table> <tr>';
while($count < count($numbers)){
echo '<td style="border:1px solid black; padding:10px;">' . $numbers[$count] . '</td>' ;
$count++;
}
echo '</table> </tr>';

echo '<p>4- Iterating with<b> the do while loop </b>through an array of numbers</p>
<table><tr>';
do {
echo '<td style="border:1px solid black; padding:7px 10px;">' . $num1 .'</td>';
$num1++;
} while ($num1 <= 10);
echo '</table> </tr>';



?>

</body>
</html>
28 changes: 28 additions & 0 deletions maths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Maths</title>
</head>
<body>
<h1>Maths.php</h1>
<?php
echo '<b>$num1 = 95.52 </b><br>';
$num1 = 95.52;
echo 'Absolute value: ' . abs($num1) . '<br>';
echo 'Rounded down value: ' . floor($num1) . '<br>';
echo 'Rounded up value: ' . round($num1) . '<br><br>';

echo '<b>$numbers = array (0.8, 9.5, 1, 25);</b><br>';
$numbers = array(0.8, 9.5, 1, 25);
echo 'Highest value: ' . max($numbers) . '<br>';
echo 'Lowest value: ' . min($numbers) . '<br><br>';

echo '<b>Random number from 0 to 40</b><br>';
echo 'Random value: ' . rand(0, 40) . '<br>';

?>
</body>
</html>
Loading