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: David Moina #72

Open
wants to merge 3 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
53 changes: 17 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
`#php` `#basics` `#master-in-software-development`
`#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.
# PHP Basics <!-- omit in toc -->

## Index <!-- omit in toc -->
> In this project I learned the basic notions of PHP, language which is so used in the world of web development.

- [Requirements](#requirements)
- [Repository](#repository)
- [Technologies used](#technologies-used)
- [Project delivery](#project-delivery)
- [Resources](#resources)
All the exercises have been done using PHP as language and using Xampp as web server.

## What I've learned

## Requirements

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

## Repository
- What is a server-side language and what it is used for.

First of all you must fork this project into your GitHub account.
- What is **XAMPP** and how to use it.

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.
- Improve GitHub knowledge.

<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
\* PHP

- [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)
## Autor
* **[David Moina](https://github.com/davidmoina)**
31 changes: 31 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
echo "<h1>Arrays</h1>";

$arr1 = array("tomato", "potato", "carrot");

echo "<p>First array: ", var_dump($arr1),"</p>";

$arr2 = array(10, 2.5 , 7, 200, 3.2);

echo "<p>Second array: ", var_dump($arr2),"</p>";

#multidimensional array
$arrMult = array("user" => array("david", "moina"), "occupation" => array("student", "employee"));

echo "<p>Multidimensional array: ", var_dump($arrMult),"</p>";

#length of an array
echo "<p>Length of second array is ", count($arr2),"</p>";

#array combination
$arrComb = array_merge($arr1, $arr2);
echo "<p>The combination of the first and second array is", var_dump($arrComb), "</p>";

#last element of an array
echo "<p>The last element of the first array is: ", end($arr1),"</p>";

# add a new element to the array
array_push($arr1, "banana");

echo "<p>Now I added banana to the first array and it is the result: ", var_dump($arr1),"</p>";
?>
55 changes: 55 additions & 0 deletions conditionals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
echo "<h1>Conditionals</h1>";

#condition that evaluates whether the current day is Monday
$day = date("l");

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

#condition that evaluates whether the current month is October
$month = date("F");

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

#double condition
$minute = date("i");

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

#switch conditional
switch($day) {
case "Monday":
echo "<p>Today is $day</p>";
break;
case "Tuesday":
echo "<p>Today is $day</p>";
break;
case "Wednesday":
echo "<p>Today is $day</p>";
break;
case "Thursday":
echo "<p>Today is $day</p>";
break;
case "Friday":
echo "<p>Today is $day</p>";
break;
case "Saturday":
echo "<p>Today is $day</p>";
break;
case "Sunday":
echo "<p>Today is $day</p>";
break;
}
?>
21 changes: 21 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
echo "<h1>Dates</h1>";

$dateVar = new DateTime();

#date with format method
echo $dateVar-> format("Y-m-d"), "<br>";

#current date in any format
echo "Current date: ", $dateVar->format('Y-m-d H:i:sP'), "<br>";

#current day
echo "Current day: ", date("l"), "<br>";

#current month in numerical format
echo "Month: ", date("m"), "<br>";

#current minute with leading zeros
echo "Current minute: ",date('i');

?>
39 changes: 39 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
echo "<h1>Functions</h1>";

#function to sum two numbers
function sum($num1, $num2) {
return $num1 + $num2;
};

echo "<p>The result of 2 + 5 = ", sum(2, 5),"</p>";

#function to multiply two numbers
function mul($num1, $num2) {
return $num1 * $num2;
}

echo "<p>The result of 2 x 5 = ", mul(2, 5),"</p>";

#function to divide two numbers
function div($num1, $num2) {
return $num1 / $num2;
}

echo "<p>The result of 10 / 2 = ", div(10, 2),"</p>";

#function
function operations($num1, $num2, $type) {
if($type == "add" || $type == "+") {
echo "$num1 + $num2 = ",sum($num1, $num2);
} elseif($type == "multiply" || $type == "*" || $type == "x") {
echo "$num1 x $num2 = ",mul($num1, $num2);
} elseif($type == "divide" || $type == "/") {
echo "$num1 / $num2 = ",div($num1, $num2);
} else {
echo "Please enter a valid operation";
}
}

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

for($i = 0; $i < 10; $i++) {
print $i;
}

print "<br>";

$arr = array("David", "Moina", 0 , 1);

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

print "<br>";

$number = 0;

while ($number <= 10) {
echo "$number ";
$number++;
}

print "<br>";

$ej = 10;

do {
echo "$ej ";
$ej--;
} while($ej > 0);

?>
21 changes: 21 additions & 0 deletions maths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
echo "<h1>mathematical operators</h1>";

#absolute value
$absValue = abs(-5);
echo "<p>The absolute value of -5 is $absValue</p>";

#rounded value
$roundedValue = ceil(2.5);
echo "<p>The rounded value to the next highest integer of 2.5 is $roundedValue</p>";

$maxValue = max(3, 4, 9, 1, 7);
echo "<p>The maximum value of (3, 4, 9, 1, 7) is $maxValue</p>";

$minValue = min(3, 4, 9, 1, 7);
echo "<p>The minimum value of (3, 4, 9, 1, 7) is $minValue</p>";

$randNum = rand();

echo "A random number: $randNum";
?>
49 changes: 49 additions & 0 deletions operators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
echo "<h1>Operators</h1>";

#arithmetic operators
print "<h3>arithmetic operators</h3>";

echo "5 + 5 = ",var_dump(5 + 5), "<br>";

echo "9 - 3 = ",var_dump(9 - 3), "<br>";

echo "3 * 10 = ",var_dump(3 * 10), "<br>";

echo "30 / 3 = ",var_dump(30 / 3), "<br>";

echo "20 % 2 = ",var_dump(20 % 2), "<br>";

#comparison operators
print "<h3>comparison operators</h3>";

echo "(1 == 2) = ",var_dump(5 + 5), "<br>";

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

echo "(3 < 5) = ",var_dump(3 < 5), "<br>";

echo "(3 > 5) = ",var_dump(3 > 5), "<br>";

echo "(5 <= 5) = ",var_dump(5 <= 5), "<br>";

echo "(5 >= 6) = ",var_dump(5 >= 6), "<br>";

#logical operators
print "<h3>logical operators</h3>";

$a = false;
$b = true;

echo "a = false, b = true <br>";

echo "(a && b) = ", var_dump($a && $b), "<br>";

echo "(a and b) = ", var_dump($a and $b), "<br>";

echo "(a || b) = ", var_dump($a || $b), "<br>";

echo "(a or b) = ", var_dump($a or $b), "<br>";

echo "(!a) = ", var_dump(!$a), "<br>";
?>
5 changes: 5 additions & 0 deletions phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
echo "<h1>PHP Info</h1>";

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 "<h1>Print</h1>";

echo "Its my first time with PHP <br>";

print "Hello my name is David <br>";

$a = array ('a' => 'manzana', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));

print_r($a);
?>
40 changes: 40 additions & 0 deletions strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
echo "<h1>Strings</h1>";

echo "<p>Hello Assembler</p>";

$name = "David";

echo $name;

echo "<p>My name is $name.</p>";

# replace text in a string
$phrase = "<p>University is great to study in it.</p>";

echo str_replace("University", "Assembler", $phrase);

$other_phrase = "<p>I like play Football</p>";

echo str_ireplace("football", "video games", $other_phrase);

#function that allows you to write a text N times
$txt = "PHP ";

echo str_repeat($txt, 5);

#length of a string
echo "<p>Length of $name: ", strlen($name), "</p>";

#obtain the position of the first occurrence of a text within a text string
echo "<p>Position of v in $name: ", strpos($name, "v"),"</p>";

#converts a string to uppercase
echo "<p>My name converted to uppercase: ", strtoupper($name),"</p>";

#converts a string to lowercase
echo "<p>My name converted to lowercase: ", strtolower($name),"</p>";

#obtain a text substring from a given position
echo "<p>A substring text of $name from a given position(2): ", substr($name, 2),"</p>"
?>
Loading