From 1b570eceba5bf13ca51a282fab8e9907e16f7e7b Mon Sep 17 00:00:00 2001 From: Joe Alt Date: Tue, 20 Dec 2022 10:08:18 +0100 Subject: [PATCH 1/3] First 3 php files --- iterators.php | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ operators.php | 106 +++++++++++++++++++++++++++++++++++ print.php | 90 ++++++++++++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 iterators.php create mode 100644 operators.php create mode 100644 print.php diff --git a/iterators.php b/iterators.php new file mode 100644 index 0000000..f36054b --- /dev/null +++ b/iterators.php @@ -0,0 +1,151 @@ + + + + + + + + File iterators.php + + + +

library of functionalities php

+

php iterators using "for"

+ + "; + + for ($i = 1;; $i++) { + if ($i > 10) { + break; + } + echo $i; + echo " "; + } + + echo "
"; + + $i = 1; + for (;;) { + if ($i > 10) { + break; + } + echo $i; + echo " "; + $i++; + } + + echo "
"; + + for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, print " ", $i++); + + + ?> + + + +

+

php iterators using "forEach"

+ + "; + + + $a = array(1, 2, 3, 17); + + $i = 0; + + foreach ($a as $v) { + echo "\$a[$i] => $v.\n"; + $i++; + } + echo "
"; + + + $a = array( + "uno" => 1, + "dos" => 2, + "tres" => 3, + "diecisiete" => 17 + ); + + foreach ($a as $k => $v) { + echo "\$a[$k] => $v.\n"; + } + echo "
"; + + + $a = array(); + $a[0][0] = "a"; + $a[0][1] = "b"; + $a[1][0] = "y"; + $a[1][1] = "z"; + + foreach ($a as $v1) { + foreach ($v1 as $v2) { + echo "$v2\n"; + } + } + echo "
"; + + + foreach (array(1, 2, 3, 4, 5) as $v) { + echo "$v\n"; + } + + ?> + + + +

+

php iterators using "while"

+ + "; + + + $i = 1; + while ($i <= 10) : + echo "$i\n"; + $i++; + endwhile; + + ?> + + + +

+

php iterators using "do while"

+ + "; + $i++; + } while ($i <= 5); + + ?> + + + + \ No newline at end of file diff --git a/operators.php b/operators.php new file mode 100644 index 0000000..bc0ebf4 --- /dev/null +++ b/operators.php @@ -0,0 +1,106 @@ + + + + + + + + File operators.php + + + +

library of functionalities php

+ + + +

php arithmetic operators

+ + "; + + + $b = 1; + $c = 2; + echo $b = $c += 3; + echo "
"; + + + $d = 1; + echo $d + $d++; + echo "
"; + + ?> + + + +

+

php comparison operators

+ + 1; + echo "
"; + + + echo 2.5 <=> 1.5; + echo "
"; + + + echo "b" <=> "a"; + echo "
"; + + + echo "zz" <=> "aa"; + echo "
"; + + + echo [1, 2, 3] <=> [1, 2, 4]; + echo "
"; + + + $a = (object) ["a" => "c"]; + $b = (object) ["a" => "b"]; + echo $a <=> $b; + + ?> + + + +

+

php logical operators

+ + + + + + \ No newline at end of file diff --git a/print.php b/print.php new file mode 100644 index 0000000..89aa120 --- /dev/null +++ b/print.php @@ -0,0 +1,90 @@ + + + + + + + + File print.php + + + +

library of functionalities php

+

php "echo" instructions

+ + + + + +

+

php "print" instructions

+ + + + + +

+

php "print_r" instructions

+ + 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); + print_r ($a); + + ?> + + + From 140e8a06508e14534dfe376ceb606d126e4e2ab9 Mon Sep 17 00:00:00 2001 From: Joe Alt Date: Tue, 20 Dec 2022 13:20:48 +0100 Subject: [PATCH 2/3] 5 second part PHP basics --- conditionals.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ dates.php | 38 ++++++++++++++++++++++++ maths.php | 49 ++++++++++++++++++++++++++++++ strings.php | 69 +++++++++++++++++++++++++++++++++++++++++++ types.php | 57 +++++++++++++++++++++++++++++++++++ 5 files changed, 290 insertions(+) create mode 100644 conditionals.php create mode 100644 dates.php create mode 100644 maths.php create mode 100644 strings.php create mode 100644 types.php diff --git a/conditionals.php b/conditionals.php new file mode 100644 index 0000000..90f63dd --- /dev/null +++ b/conditionals.php @@ -0,0 +1,77 @@ + + + + + + + + File conditionals.php + + + +

library of functionalities php

+

php conditionals

+ + "; + + + $month = date("F"); + + if ($month == "October") { + echo "We are in October"; + } else { + echo "We aren't in October. We are in " . $month; + } + print "
"; + + + $minute = date("i"); + + if ($minute < 10) { + echo "The current minute is less than 10"; + } else if ($minute > 15) { + echo "The current minute is more than 15"; + } else { + echo "Does not meet any conditions"; + } + print "
"; + + + $switchDay = date("l"); + + switch ($switchDay) { + case "Monday": + echo "Happy Monday"; + break; + case "Tuesday": + echo "Happy Tuesday"; + break; + case "Wednesday": + echo "Happy Wednesday"; + break; + case "Thursday": + echo "Happy Thursday"; + break; + case "Friday": + echo "Happy Friday"; + break; + case "Saturday": + echo "Happy Saturday"; + break; + case "Sunday": + echo "Happy Sunday"; + break; + } + + ?> + + + + \ No newline at end of file diff --git a/dates.php b/dates.php new file mode 100644 index 0000000..f06b9b8 --- /dev/null +++ b/dates.php @@ -0,0 +1,38 @@ + + + + + + + + File dates.php + + + +

library of functionalities php

+

php DateTime class

+ + format('Y-m-d'); + echo "
"; + + echo $objDateTime->format(DateTimeInterface::COOKIE); + echo "
"; + + echo "Today is " . date("l"); + echo "
"; + + echo "Current month in numerical format " . date("m"); + echo "
"; + + echo "Current minute with leading zeros " . date("i"); + echo "
"; + + ?> + + + + \ No newline at end of file diff --git a/maths.php b/maths.php new file mode 100644 index 0000000..db934df --- /dev/null +++ b/maths.php @@ -0,0 +1,49 @@ + + + + + + + + File maths.php + + + +

library of functionalities php

+

php maths

+ + + + "; + + + echo ceil(4.3) . "
"; + + + function highestValue() { + $hValue = [12,34,6,132,74,28,131,98]; + return max($hValue); + } + echo highestValue() . "
"; + + + function lowestValue() { + $lValue = [12,34,6,132,74,28,131,98]; + return min($lValue); + } + echo lowestValue() . "
"; + + + function randomValue() { + return rand(1, 10); + } + echo randomValue(); + + ?> + + + + \ No newline at end of file diff --git a/strings.php b/strings.php new file mode 100644 index 0000000..0ffc777 --- /dev/null +++ b/strings.php @@ -0,0 +1,69 @@ + + + + + + + + File strings.php + + + +

library of functionalities php

+

php strings

+ + "; + + $var = "Printing a text string that interpret variables"; + print $var . "
"; + + $name = "Jhon"; + $age = 23; + print "The age of $name is $age
"; + + + $strictlyPhrase = "You should eat fruits, vegetables, and fiber every day."; + $strictlyHealthy = array("fruits", "vegetables", "fiber"); + $strictlyYummy = array("pizza", "chips", "ice cream"); + + $strictlyNewPhrase = str_replace($strictlyHealthy, $strictlyYummy, $strictlyPhrase); + print $strictlyNewPhrase . "
"; + + + $replacePhrase = "You should eat fruits, vegetables, and fiber every day."; + $replaceHealthy = array("fruits", "vegetables", "fiber"); + $replaceYummy = array("pizza", "chips", "ice cream"); + + $replaceNewPhrase = str_replace($replaceHealthy, $replaceYummy, $replacePhrase); + print $replaceNewPhrase . "
"; + + + $i = 1; + while ($i <= 6) : + echo "This text will repeat it self
"; + $i++; + endwhile; + + + $textString = "awesome"; + echo "Awesome has " . strlen($textString) . " characters.
"; + + + $mystring = 'abcdefg'; + $findme = 'e'; + $pos = strpos($mystring, $findme); + echo $pos . "
"; + + echo ucfirst("hello everyone") . "
"; + + echo strtolower("I'm LOVING It to CODE") . "
"; + + echo substr("abcdef", 2, -1) . " from abcdef"; + + ?> + + + + \ No newline at end of file diff --git a/types.php b/types.php new file mode 100644 index 0000000..8035192 --- /dev/null +++ b/types.php @@ -0,0 +1,57 @@ + + + + + + + + File types.php + + + +

library of functionalities php

+

php types

+ + + + "; + + $million = 1000000; + $integer = 50000000000000 * $million; + var_dump($integer); + echo "
"; + + + $a = "1234.56789"; + echo floatval($a) . "
"; + + + echo 'Arnold once said: "I\'ll be back"' . "
"; + + + $array = array( + 1 => "a", + "1" => "b", + 1.5 => "c", + true => "d", + ); + var_dump($array); + echo "
"; + + + $obj = (object) array('1' => 'foo'); + var_dump(isset($obj->{'1'})); + echo "
"; + + + $var = NULL; + echo "\$var = null;" + + ?> + + + + \ No newline at end of file From 1750e818f844d7362c7fc2bc98b25d5ee8b32984 Mon Sep 17 00:00:00 2001 From: Joe Alt Date: Tue, 20 Dec 2022 14:11:03 +0100 Subject: [PATCH 3/3] added last 3 files. added back button on all pages --- arrays.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ conditionals.php | 1 + dates.php | 1 + functions.php | 36 ++++++++++++++++++++++++++++++++++++ iterators.php | 1 + maths.php | 1 + operators.php | 1 + phpinfo.php | 5 +++++ print.php | 1 + strings.php | 1 + types.php | 1 + 11 files changed, 94 insertions(+) create mode 100644 arrays.php create mode 100644 functions.php create mode 100644 phpinfo.php diff --git a/arrays.php b/arrays.php new file mode 100644 index 0000000..8ea7ff2 --- /dev/null +++ b/arrays.php @@ -0,0 +1,45 @@ + + + + + + + + File arrays.php + + + +⮜Go Back +

library of functionalities php

+

php arrays

+ + "; + + $simpleArrs = $simpleArrString + $simpleArrNumDec; + var_dump($simpleArrs); + echo "
"; + + echo end($simpleArrString); + echo "
"; + + array_push($simpleArrNumDec, 123, 456, 789); + print_r($simpleArrNumDec); + + ?> + + + + \ No newline at end of file diff --git a/conditionals.php b/conditionals.php index 90f63dd..521499d 100644 --- a/conditionals.php +++ b/conditionals.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php conditionals

diff --git a/dates.php b/dates.php index f06b9b8..b94b9da 100644 --- a/dates.php +++ b/dates.php @@ -9,6 +9,7 @@ + ⮜Go Back

library of functionalities php

php DateTime class

diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..5366419 --- /dev/null +++ b/functions.php @@ -0,0 +1,36 @@ + + + + + + + + File functions.php + + + +⮜Go Back +

library of functionalities php

+

php functions

+ + "; + + $mul = $first * $second; + echo "Result: " . $mul . "
"; + + $dis = $first / $second; + echo "Result: " . $dis . "
"; + + $opr = $first - $second; + echo "Result: " . $opr . "
"; + + ?> + + + + \ No newline at end of file diff --git a/iterators.php b/iterators.php index f36054b..5bf8be1 100644 --- a/iterators.php +++ b/iterators.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php iterators using "for"

diff --git a/maths.php b/maths.php index db934df..91c1ba0 100644 --- a/maths.php +++ b/maths.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php maths

diff --git a/operators.php b/operators.php index bc0ebf4..95ec456 100644 --- a/operators.php +++ b/operators.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

\ No newline at end of file diff --git a/print.php b/print.php index 89aa120..c4dfd74 100644 --- a/print.php +++ b/print.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php "echo" instructions

diff --git a/strings.php b/strings.php index 0ffc777..88f28cf 100644 --- a/strings.php +++ b/strings.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php strings

diff --git a/types.php b/types.php index 8035192..7f10577 100644 --- a/types.php +++ b/types.php @@ -9,6 +9,7 @@ +⮜Go Back

library of functionalities php

php types