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 Pablo Herrero #85

Open
wants to merge 9 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
28 changes: 28 additions & 0 deletions arrays.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$array = ["hello", "how", "are", "you", "?"];
print_r ($array);
echo "<br>";

$array2 = [1, 2, 3.5, 4, 5.5];
print_r ($array2);
echo "<br>";

$array3 = [["hello" , "and", "welcome"], ["how", "are", "you", "?"]];
print_r ($array3);
echo "<br>";

echo "length: ", count($array);
echo "<br>";

$arrayMerge = array_merge($array3, $array);
print_r ($arrayMerge);
echo "<br>";

echo "last element of the first array is: ", end($array);
echo "<br>";

array_push($array, "Hello");
print_r ($array);

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

$currentDate = new DateTime();
if(date(format: "D") == "Mon"){
echo "we are in monday";
echo "<br>";
}

if(date(format: "M") == "Oct"){
echo "we are in October";
echo "<br>";
} else {
echo date(format: "F");
echo "<br>";
}

if(date(format: "i") < 10){
echo "the current minute is less than 10";
echo "<br>";
} else if (date(format: "i") > 15){
echo "the current minute is more than 15";
echo "<br>";
} else {
echo "does not meet any condition";
echo "<br>";
}

$switchDate = date(format: "N");
switch ($switchDate){
case 1:
echo "Hey! It's Monday";
echo "<br>";
break;
case 2:
echo "Hey! It's Tuesday";
echo "<br>";
break;
case 3:
echo "Hey! It's Wednesday";
echo "<br>";
break;
case 4:
echo "Hey! It's Thursday";
echo "<br>";
break;
case 5:
echo "Hey! It's Friday";
echo "<br>";
break;
case 6:
echo "Hey! It's Saturday";
echo "<br>";
break;
case 7:
echo "Hey! It's Sunday";
echo "<br>";
break;

}
?>
13 changes: 13 additions & 0 deletions dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
$date = new DateTime();
echo $date->format('Y-M-d');
echo "<br>";
echo date(format: "y-m-d");
echo "<br>";
echo date(format: "D");
echo "<br>";
echo date(format: "m");
echo "<br>";
echo date('i');

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


function sum($x, $y) {
return $x + $y;
}
echo "2 + 3 = ";
echo sum(2, 3);
echo "<br>";

function multi($x, $y) {
return $x * $y;
}
echo "2 * 3 = ";
echo multi(2, 3);
echo "<br>";

function div($x, $y) {
return $x / $y;
}
echo "2 / 3 = ";
echo div(2, 3);
echo "<br>";

function chooseOp($y, $x, $operando) {
if ($operando === "+") {
return $y + $x;
}else if ($operando === "-") {
return $y - $x;
}else if ($operando === "*") {
return $y * $x;
}else if ($operando === "/") {
return $y / $x;
}else if ($operando === "%") {
return $y % $x;
}else if ($operando === "**") {
return $y ** $x;
}
}
echo "2 ** 3 = ";
echo chooseOp(2, 3, "**");
echo "<br>";
?>
41 changes: 41 additions & 0 deletions iterators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
$i = 0;
for($i = 0; $i < 4; $i++){
echo "i in for is: ";
print_r ($i);
echo "<br>";
}

echo "<br>";

$array = array(1, 2, 3, 4);
echo "array before forEach: ";
print_r ($array);
echo "<br>";
foreach ($array as &$valor) {
$valor++;
}
//unset($valor);

echo "array after forEach: ";
print_r ($array);

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

$j = 0;
while($j<10){
echo "j in while is: $j";
echo "<br>";
$j++;
}

echo "<br>";

$k = 0;
do{
echo "k in do while is: $k";
echo "<br>";
$k++;
}while($k < 10);

?>
25 changes: 25 additions & 0 deletions math.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
echo "absolute value of -5: ";
$num = abs(-5);
echo "$num";
echo "<br>";

$rounded = round(6.5);
echo "6.5 rounded is: ";
echo "$rounded";
echo "<br>";

$maxNum = max(2, 3, 4, 5);
echo "the max number between 2, 3, 4, and 5 is: ";
echo $maxNum;
echo "<br>";

$minNum = min(2, 3, 4, 5);
echo "the min number between 2, 3, 4, and 5 is: ";
echo $minNum;
echo "<br>";

echo "random number between 1 and 10: ";
echo rand(1, 10);
echo "<br>";
?>
74 changes: 74 additions & 0 deletions operators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
$var1 =2;
$var2 = 3;
$var3 = 5;
$bool1 = true;
$bool2 = true;
$bool3 = false;

$var4 = $var1 + $var2;
echo "2 + 3 = ";
print_r($var4);

echo "<br>";

$var4 = $var1 - $var2;
echo "2 - 3 = ";
print_r($var4);

echo "<br>";

$var4 = $var1 * $var2;
echo "2 * 3 = ";
print_r($var4);

echo "<br>";

$var4 = $var1 / $var2;
echo "2 / 3 = ";
print_r($var4);

echo "<br>";

echo "1 = 2? ";
var_dump(1 == 2);

echo "<br>";
echo "1 != 2?";
var_dump(1 != 2);

echo "<br>";
echo "1 < 2? ";
var_dump(1 < 2);

echo "<br>";
echo "1 > 2? ";
var_dump(1 > 2);

echo "<br>";
echo "1 <= 2? ";
var_dump(1 <= 2);

echo "<br>";
echo "1 >= 2? ";
var_dump(1 >= 2);
echo "<br>";

echo "true && true: ";
var_dump($bool1 && $bool2);
echo "<br>";

echo "true || false: ";
var_dump($bool1 || $bool3);
echo "<br>";

echo "!false: ";
var_dump(!$bool3);
echo "<br>";

echo "true XOR false: ";
var_dump($bool1 xor $bool3);
echo "<br>";


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

phpinfo();
?>
9 changes: 9 additions & 0 deletions print.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

echo "This is an echo instruction", "<br>", "this is also an echo instruction";
echo "<br>";
print "this is a print instruction";
echo "<br>";
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
39 changes: 39 additions & 0 deletions strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

echo "this is a printed string";
echo "<br>";

$a = "this is a string printed with a variable";
print_r ($a);
echo "<br>";

echo "{$a} and concatenated with text";
echo "<br>";

$strin = "I like Lasagna";
print_r(str_replace("Lasagna", "Pasta", $string));
echo "<br>";

$string = "I like Lasagna";
print_r(str_ireplace("lasagNA", "pasta", $string));
echo "<br>";

$repeatString = "hello <br>";
echo str_repeat($repeatString, 10);

$stringLength = "This is a string";
echo strlen($stringLength);
echo "<br>";

echo strpos("This is a string", "string");
echo "<br>";

$anotherString = "this is yet another string";
echo strtoupper($anotherString);
echo "<br>";

echo strtolower($anotherString);
echo "<br>";

echo substr($anotherString, 11);
?>
32 changes: 32 additions & 0 deletions types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
$bool = true;
var_dump($bool);
echo "<br>";

$int = 5;
var_dump($int);
echo "<br>";

$float = 5.0;
var_dump($float);
echo "<br>";

$string = "hello";
var_dump($string);
echo "<br>";

$array = [1, 2, 3];
var_dump($array);
echo "<br>";

$object = (object) [
'propertyOne' => 'foo',
'propertyTwo' => 42,
];
var_dump($object);
echo "<br>";

$null;
var_dump($null);
echo "<br>";
?>