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: Álvaro Sánchez #77

Open
wants to merge 4 commits 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
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`#php` `#basics` `#master-in-software-development`

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

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
Expand All @@ -10,37 +10,23 @@
>
> 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 -->
## Index

- [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
- Have a XAMPP software installed

## 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)
Expand Down
35 changes: 35 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$animals = array("dog", "cat", "wolf", "parrot", "monkey");

$numbers = array(1,2.2,3,3.3,4,4.4);

$species = array(
array("dog", "wolf", "coyote"),
array("cat", "tiger", "lion"),
array("macaque", "mandrill", "baboon"),
);

function lengthArray ($numbers){
return count($numbers);
}
echo count($numbers);
echo "<br>";

function arrayMerge() {
return array_merge($animals, $numbers);
};
print_r(array_merge($animals, $numbers));
echo "<br>";

function lastElement($animals){
return end($animals);
};
echo end($animals);
echo "<br>";


array_push($numbers, 5, 5.5);
print_r($numbers);

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

echo "<h3>Are we on Monday?</h3>";

if (date("w") == 1) {
echo "Today is Monday <br>";
} else{
echo "today isn´t Monday";
}
echo "<br><br>";

echo "<h3>conditional to check if the current month is October</h3>";

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

echo "<h3>doble condicional about current minute</h3>";


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 "<br><br>";
//podrias crear una variable para los dates (date("i"), date("F") y date("w")) rollo $min, $month y $day

echo "<h3>Daily message with switch</h3>";

$day = date("w");

switch($day) {
case 1:
echo "Today is Monday :(";
break;

case 2:
echo "today is Tuesday :(";
break;

case 3:
echo "today is Wednesday :|";
break;

case 4:
echo "today is Thursday :|";
break;

case 5:
echo "today is Friday :)";
break;

case 6:
echo "today is Saturday :D";
break;

case 0:
echo "today is Sunday :)";
break;
}



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

echo "<h3>Instance the DateTime!</3>";

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

echo "<h3>get the current day in any format</3>";
echo "<br>";

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

echo "<h3>get the current day</3>";
echo "<br>";

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

echo "<h3>Get the current month in numerical format (1-12)</3>";
echo "<br>";

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

echo "<h3>Get the current minute with leading zeros (00 - 59)</3>";
echo "<br>";

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


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

echo "<h3>Create a function that given two numbers returns the sum of both</h3>";

function sum($a, $b) {
return $a + $b;
}
echo sum(14, 26);
echo "<br>";

echo "<h3>Create a function that given two numbers returns the multiplication of both</h3>";

function multiplication($a, $b) {
return $a * $b;
}
echo multiplication(14, 3);
echo "<br>";

echo "<h3>Create a function that given two numbers returns the division of both</h3>";

function division($a, $b) {
return $a / $b;
}
echo division(14, 3);
echo "<br>";

echo "<h3>Create a function that, given two numbers and an operation (add, multiply or divide), returns the result of that operation.</h3>";

function operation($a, $operator, $b){
if($operator == '+'){
echo sum($a,$b);
}else if($operator == '*'){
echo multiplication($a,$b);
}else if($operator == '/'){
echo division($a,$b);
}else{
echo "Error";
}
}
operation(3, "+", 4);
echo "<br>";
operation(3, "*", 4);
echo "<br>";
operation(3, "/", 4);

?>
32 changes: 32 additions & 0 deletions iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
echo "<h3>for loop</h3>";
for ($i = 0; $i <= 8; $i++){
echo $i;
}

echo "<h3>for each</h3>";
$array = ["bread","milk","onions","eggs"];
foreach ($array as $valor) {
print "$valor";
}

echo "<h3>While</h3>";

$num = 1;

while($num <= 5) {
echo $num;
$num++;
}

echo "<h3>Do while</h3>";

$numero = 1;

do{
echo $numero;
$numero++;
}
while($numero < 6);

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

$number = 33.33;
function absolute($number) {
return abs($number);
}
echo abs($number);
echo "<br>";

function rounded($number) {
return ceil($number);
}
echo ceil($number);
echo "<br>";

$myArray = array(2,4,6,8,10,12);
function lowestValue($myArray) {
return min($myArray);
}
echo min($myArray);
echo "<br>";

function highestValue($myArray) {
return max($myArray);
}
echo max($myArray);
echo "<br>";

function random() {
return rand(1, 1000);
}
echo rand(1, 1000);
echo "<br>";

absolute($number);
rounded($number);
lowestValue($myArray);
highestValue($myArray);
random();

?>
50 changes: 50 additions & 0 deletions operators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
echo "<h3>arithmetic operators</h3>";
echo '<pre>
var_dump(12 + 12 == 24);
var_dump(12 - 12 == 24);
var_dump(12 * 12 == 144);
var_dump(12 / 12 == 12);
var_dump(12 % 12 == 24);
</pre>';
var_dump(12 + 12 == 24);
echo "<br>";
var_dump(12 - 12 == 24);
echo "<br>";
var_dump(12 * 12 == 144);
echo "<br>";
var_dump(12 / 12 == 12);
echo "<br>";
var_dump(12 % 12 == 24);

echo "<h3>comparison operators</h3>";

echo '<pre>
var_dump(3==4);
var_dump(3!=4);
var_dump(3<4);
var_dump(3>4);
var_dump(3<=4);
var_dump(3>=4);
</pre>';

var_dump(3==4);
echo "<br>";
var_dump(3!=4);
echo "<br>";
var_dump(3<4);
echo "<br>";
var_dump(3>4);
echo "<br>";
var_dump(3<=4);
echo "<br>";
var_dump(3>=4);

echo "<h3>Logical operators</h3>";

var_dump(2 < 3 && 4 > 8);
var_dump(2 > 3 || 7 > 1);
var_dump(2 < 3 xor 4 > 8); #devuelve true solo si uno es true y el otro no lo es
var_dump(! 2!=3); # devuelve true si X no es true

?>
3 changes: 3 additions & 0 deletions phpinfo/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
phpinfo();
?>
11 changes: 11 additions & 0 deletions print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
echo "<h3>Instruction with echo</h3>";
echo 'bread',",",' milk',",",' onions...';

echo "<h3>Instruction with print</h3>";
print "bread, milk, onions...";

echo "<h3>Instruction with print_r</h3>";
$shoppingList = array("bread","milk","onions","eggs");
print_r($shoppingList);
?>
Loading