Skip to content
48 changes: 16 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,35 @@
`#php` `#basics` `#master-in-software-development`
## PHP Intro & Basics

# PHP Basics <!-- omit in toc -->
In this repository you will find all the basic syntax and part of the basic concepts, in addition, you will find basic code snippets which are frequently used in PHP.

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
</p>
## Prerequisites
It is important that before starting you have an environment capable of running PHP.
If you want, you can download XAMPP, this software will allow you to have an entire environment at your disposal to carry out your developments.
This software brings you together everything you need like: web technologies ,web server, php interpreter and a MariaDB database.

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

## Index <!-- omit in toc -->
## Fork
- [Forked from assembler-institute/php-basics](https://github.com/assembler-institute/php-basics.git)

- [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
\* PHP, XAMPP, VSCODE

## 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)
- [What can PHP do?-2](https://www.w3schools.com/php/default.asp)
- [DateTime class](https://www.youtube.com/watch?v=TP1jXmcrWIs)
- [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)

## Author

Dayan Álvarez Martínez

83 changes: 83 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
# Simple array composed of text strings

echo ("<i>Simple array composed of text strings: (array() or []) </i> <br>");

echo ('method: array("Ho", "Ho", "Ho", "Ho")');
echo ("<br>");
echo ('method: ["He", "He", "He", "He"]');

echo ("<hr>");

# Simple array consisting of whole numbers and decimal numbers

echo ("<i>Simple array consisting of whole numbers and decimal numbers: 1, 2.3, 3.5, -4 (array() or []) </i> <br>");

echo ('method: array(1, 2.3, 3.5, -4)');
echo ("<br>");
echo ('method: [1, 2.3, 3.5, -4]');

echo ("<hr>");

# Multidimensional array

echo ("Multidimensional array: <br>");

$cars = array (
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);

echo '<pre>'; print_r($cars); echo '</pre>';

echo ("<hr>");

# Obtain the length of an array

echo ("<i>Obtain the length of an array (count()). </i> <br>");

$cars = array (
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);

echo ("Length: " . count($cars));

echo ("<hr>");

# Obtain the combination of two arrays

echo ("<i>Obtain the combination of two arrays(array_merge()). </i> <br>");

$array1 = array("color", "red", 2, 4);
$array2 = array("a", "b", "color", "shape", 4);
$result = array_merge($array1, $array2);
echo '<pre>1-'; print_r($array1); echo '</pre>';
echo '<pre>2-'; print_r($array2); echo '</pre>';
echo '<pre>Merged-'; print_r($result); echo '</pre>';

echo ("<hr>");

# Obtain the last element of an array

echo ("<i>Obtain the last element of an array(end()). </i> <br>");

$array1 = array("color", "red", 2.32, "cars");
echo '<pre>'; print_r($array1); echo '</pre>';
echo ("the las element is: " . end($array1));

echo ("<hr>");

# Add a new element to the array

echo ("<i>Add a new element to the array(array_push()). </i> <br><br>");

$stack = array("orange", "banana");
echo '<pre>before: '; print_r($stack); echo '</pre>';
array_push($stack, "apple", "raspberry");
echo '<pre>after: '; print_r($stack); echo '</pre>';
?>
74 changes: 74 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
echo ("<h1>Conditionals</h1>");

# If current day is Monday

echo ("Current day condition: ");
if(date("D") === "Mon") {
echo ("We are on Monday");
}else{
echo ("It is not Monday");
}

echo ("<hr>");

# If current month is October

echo ("Current month condition: ");
if(date("M") === "Oct") {
echo ("We are on October");

}else{
echo date("M");
}

echo ("<hr>");


# Current minute condition

echo ("Current Minute condition: ");

if (date("i") < 10) {
echo ("The current minute is less than 10");
}else if (date("i") > 15) {
echo ("The current minute is more than 15");
}else {
echo ("Does not meet any conditions");
}

echo ("<hr>");


# Day of the week


echo ("Day of the week with switch: ");



switch (date("w")) {
case 0:
echo ("Today it is Sunday");
break;
case 1:
echo ("Today it is Monday");
break;
case 2:
echo ("Today it is Tuesday");
break;
case 3:
echo ("Today it is Wednesday");
break;
case 4:
echo ("Today it is Thursday");
break;
case 5:
echo ("Today it is Friday");
break;
case 6:
echo ("Today it is Saturday");
break;

}
?>
32 changes: 32 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
echo ("<h1>Dates</h1>");

# Date Time class

$dateClass = new DateTime();
print("Y-m-d format: ");
echo $dateClass->format("Y-m-d");

echo ("<hr>");

# Current date
print("Current date in any format: ");
echo $dateClass->format("y-M-l");

echo ("<hr>");

print("Current day: ");
echo $dateClass->format("l");

echo ("<hr>");

print("Current month in numerical: ");
echo $dateClass->format("m");

echo ("<hr>");

print("Current minute leading zeros: ");
echo $dateClass->format("00:i");


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

# Function that given two numbers returns the sum of both

echo("<i>Function that given two numbers returns the sum of both. </i> <br>");


function sum($x, $y) {
return $x + $y;
}
echo '<pre>'; print_r("function sum(x, y) {
return x, y; <br>}"); echo '</pre>';
echo ("returned: " . sum(4, 6));

echo ("<hr>");

# Function that given two numbers returns the multiplication of both

echo("<i>Function that given two numbers returns the multiplication of both. </i> <br>");


function multiplication($x, $y) {
return $x * $y;
}
echo '<pre>'; print_r("function sum(x, y) {
return x * y; <br>}"); echo '</pre>';
echo ("returned: " . multiplication(4, 6));

echo ("<hr>");

# Function that given two numbers returns the division of both


echo("<i>Function that given two numbers returns the division of both
. </i> <br>");


function division($x, $y) {
return $x * $y;
}
echo '<pre>'; print_r("function sum(x, y) {
return x * y; <br>}"); echo '</pre>';
echo ("returned: " . division(4, 6));

echo ("<hr>");

# Function that given two numbers and an operation (add, multiply or divide), returns the result of that operation


echo("<i>Function that given two numbers and an operation (add, multiply or divide), returns the result of that operation. </i> <br>");

function xOperation($y, $x, $operation) {
if ($operation === "+") {
return $y + $x;
}else if ($operation === "-") {
return $y - $x;
}else if ($operation === "*") {
return $y * $x;
}else if ($operation === "/") {
return $y / $x;
}else if ($operation === "%") {
return $y % $x;
}else if ($operation === "**") {
return $y ** $x;
}

}

echo '<pre>'; print_r("function operation() {
if (operation = `+`) {
return y + x;
}else if (operation = `-`) {
return y - x;
}else if (operation = `*`) {
return y * x;
}else if (operation = `/`) {
return y / x;
}else if (operation = `%`) {
return y % x;
}else if (operation = `**`) {
return y ** x;
}
}"); echo '</pre>';

echo ("returned: " . xOperation(4, 5, "+"));

?>


43 changes: 43 additions & 0 deletions iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
echo ("<h1>Iterators</h1>");

# For loop example

$number = 0;
echo "for loop: ";
for ($i = 0; $i <= 5; $i++) {
echo "$i";
}
echo"<hr>";

# Foreach loop example

echo "Foreach loop: <br>";
$colors = array("red", "green", "blue", "yellow");

foreach ($colors as $value) {
echo "$value<br>";
}

echo"<hr>";

# While loop example

echo "While loop: ";
$integer = 0;
while($integer <= 5){
echo "$integer";
$integer++;
}

echo"<hr>";

# Do while loop example

echo "Do while loop: <br>";
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
Loading