diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..6648d8a --- /dev/null +++ b/arrays.php @@ -0,0 +1,28 @@ +"; + +$array2 = [1, 2, 3.5, 4, 5.5]; +print_r ($array2); +echo "
"; + +$array3 = [["hello" , "and", "welcome"], ["how", "are", "you", "?"]]; +print_r ($array3); +echo "
"; + +echo "length: ", count($array); +echo "
"; + +$arrayMerge = array_merge($array3, $array); +print_r ($arrayMerge); +echo "
"; + +echo "last element of the first array is: ", end($array); +echo "
"; + +array_push($array, "Hello"); +print_r ($array); + +?> \ No newline at end of file diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..d8ad0cb --- /dev/null +++ b/conditionals.php @@ -0,0 +1,60 @@ +"; +} + +if(date(format: "M") == "Oct"){ + echo "we are in October"; + echo "
"; +} else { + echo date(format: "F"); + echo "
"; +} + +if(date(format: "i") < 10){ + echo "the current minute is less than 10"; + echo "
"; +} else if (date(format: "i") > 15){ + echo "the current minute is more than 15"; + echo "
"; +} else { + echo "does not meet any condition"; + echo "
"; +} + +$switchDate = date(format: "N"); +switch ($switchDate){ + case 1: + echo "Hey! It's Monday"; + echo "
"; + break; + case 2: + echo "Hey! It's Tuesday"; + echo "
"; + break; + case 3: + echo "Hey! It's Wednesday"; + echo "
"; + break; + case 4: + echo "Hey! It's Thursday"; + echo "
"; + break; + case 5: + echo "Hey! It's Friday"; + echo "
"; + break; + case 6: + echo "Hey! It's Saturday"; + echo "
"; + break; + case 7: + echo "Hey! It's Sunday"; + echo "
"; + break; + +} +?> \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..de490d5 --- /dev/null +++ b/dates.php @@ -0,0 +1,13 @@ +format('Y-M-d'); +echo "
"; +echo date(format: "y-m-d"); +echo "
"; +echo date(format: "D"); +echo "
"; +echo date(format: "m"); +echo "
"; +echo date('i'); + +?> \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..481b827 --- /dev/null +++ b/functions.php @@ -0,0 +1,43 @@ +"; + +function multi($x, $y) { + return $x * $y; +} +echo "2 * 3 = "; +echo multi(2, 3); +echo "
"; + +function div($x, $y) { + return $x / $y; +} +echo "2 / 3 = "; +echo div(2, 3); +echo "
"; + +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 "
"; +?> \ No newline at end of file diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..c9a5175 --- /dev/null +++ b/iterators.php @@ -0,0 +1,41 @@ +"; +} + +echo "
"; + +$array = array(1, 2, 3, 4); +echo "array before forEach: "; +print_r ($array); +echo "
"; +foreach ($array as &$valor) { + $valor++; +} +//unset($valor); + +echo "array after forEach: "; +print_r ($array); + +echo "
", "
"; + +$j = 0; +while($j<10){ + echo "j in while is: $j"; + echo "
"; + $j++; +} + +echo "
"; + +$k = 0; +do{ + echo "k in do while is: $k"; + echo "
"; + $k++; +}while($k < 10); + +?> \ No newline at end of file diff --git a/math.php b/math.php new file mode 100644 index 0000000..53f5970 --- /dev/null +++ b/math.php @@ -0,0 +1,25 @@ +"; + +$rounded = round(6.5); +echo "6.5 rounded is: "; +echo "$rounded"; +echo "
"; + +$maxNum = max(2, 3, 4, 5); +echo "the max number between 2, 3, 4, and 5 is: "; +echo $maxNum; +echo "
"; + +$minNum = min(2, 3, 4, 5); +echo "the min number between 2, 3, 4, and 5 is: "; +echo $minNum; +echo "
"; + +echo "random number between 1 and 10: "; +echo rand(1, 10); +echo "
"; +?> \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..d6a9311 --- /dev/null +++ b/operators.php @@ -0,0 +1,74 @@ +"; + +$var4 = $var1 - $var2; +echo "2 - 3 = "; +print_r($var4); + +echo "
"; + +$var4 = $var1 * $var2; +echo "2 * 3 = "; +print_r($var4); + +echo "
"; + +$var4 = $var1 / $var2; +echo "2 / 3 = "; +print_r($var4); + +echo "
"; + +echo "1 = 2? "; +var_dump(1 == 2); + +echo "
"; +echo "1 != 2?"; +var_dump(1 != 2); + +echo "
"; +echo "1 < 2? "; +var_dump(1 < 2); + +echo "
"; +echo "1 > 2? "; +var_dump(1 > 2); + +echo "
"; +echo "1 <= 2? "; +var_dump(1 <= 2); + +echo "
"; +echo "1 >= 2? "; +var_dump(1 >= 2); +echo "
"; + +echo "true && true: "; +var_dump($bool1 && $bool2); +echo "
"; + +echo "true || false: "; +var_dump($bool1 || $bool3); +echo "
"; + +echo "!false: "; +var_dump(!$bool3); +echo "
"; + +echo "true XOR false: "; +var_dump($bool1 xor $bool3); +echo "
"; + + +?> \ No newline at end of file diff --git a/phpinfo.php b/phpinfo.php new file mode 100644 index 0000000..d7c3469 --- /dev/null +++ b/phpinfo.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..04f2e8d --- /dev/null +++ b/print.php @@ -0,0 +1,9 @@ +", "this is also an echo instruction"; +echo "
"; +print "this is a print instruction"; +echo "
"; +$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); +print_r ($a); +?> \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..386007e --- /dev/null +++ b/strings.php @@ -0,0 +1,39 @@ +"; + +$a = "this is a string printed with a variable"; +print_r ($a); +echo "
"; + +echo "{$a} and concatenated with text"; +echo "
"; + +$strin = "I like Lasagna"; +print_r(str_replace("Lasagna", "Pasta", $string)); +echo "
"; + +$string = "I like Lasagna"; +print_r(str_ireplace("lasagNA", "pasta", $string)); +echo "
"; + +$repeatString = "hello
"; +echo str_repeat($repeatString, 10); + +$stringLength = "This is a string"; +echo strlen($stringLength); +echo "
"; + +echo strpos("This is a string", "string"); +echo "
"; + +$anotherString = "this is yet another string"; +echo strtoupper($anotherString); +echo "
"; + +echo strtolower($anotherString); +echo "
"; + +echo substr($anotherString, 11); +?> \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..753309c --- /dev/null +++ b/types.php @@ -0,0 +1,32 @@ +"; + +$int = 5; +var_dump($int); +echo "
"; + +$float = 5.0; +var_dump($float); +echo "
"; + +$string = "hello"; +var_dump($string); +echo "
"; + +$array = [1, 2, 3]; +var_dump($array); +echo "
"; + +$object = (object) [ + 'propertyOne' => 'foo', + 'propertyTwo' => 42, + ]; +var_dump($object); +echo "
"; + +$null; +var_dump($null); +echo "
"; +?> \ No newline at end of file