From 253f7ccd8209af45c7724bf750ed4665ce029dc6 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 11 Oct 2023 09:53:41 -0400 Subject: [PATCH 01/22] Initial setup --- php/README.md | 12 ++ php/php-core/README.md | 14 +++ php/php-core/control-flow-i-php/README.md | 12 ++ .../comparison-operators-php.md | 99 ++++++++++++++++ .../if-else-statements-php.md | 70 +++++++++++ .../control-flow-i-php/if-statements-php.md | 76 ++++++++++++ .../nested-if-else-statements-php.md | 109 ++++++++++++++++++ php/php-core/intro-to-php/README.md | 12 ++ .../intro-to-php/first-program-php.md | 72 ++++++++++++ .../intro-to-php/installing-php-locally.md | 36 ++++++ php/php-core/intro-to-php/what-is-php.md | 42 +++++++ php/php-core/intro-to-php/why-learn-php.md | 23 ++++ php/php-core/logical-operators-php/README.md | 14 +++ php/php-core/logical-operators-php/and-php.md | 94 +++++++++++++++ .../and-precedence-php.md | 106 +++++++++++++++++ php/php-core/logical-operators-php/not-php.md | 76 ++++++++++++ php/php-core/logical-operators-php/or-php.md | 93 +++++++++++++++ .../what-are-logical-operators-php.md | 30 +++++ php/php-core/logical-operators-php/xor-php.md | 78 +++++++++++++ php/php-core/looping-php/README.md | 12 ++ .../looping-php/do-while-loops-php.md | 72 ++++++++++++ .../looping-php/for-each-loops-php.md | 84 ++++++++++++++ php/php-core/looping-php/for-loops-php.md | 65 +++++++++++ .../looping-php/what-are-loops-php.md | 20 ++++ php/php-core/looping-php/while-loops-php.md | 73 ++++++++++++ php/php-core/more-data-types-php/README.md | 12 ++ .../array-functions-php.md | 45 ++++++++ .../more-data-types-php/arrays-php.md | 97 ++++++++++++++++ .../variables-and-data-types-php/README.md | 16 +++ .../assignment-operators-php.md | 70 +++++++++++ .../basic-data-types-php-ii.md | 29 +++++ .../basic-data-types-php-iii.md | 20 ++++ .../basic-data-types-php-iv.md | 19 +++ .../basic-data-types-php.md | 42 +++++++ .../creating-and-storing-variables-in-php.md | 85 ++++++++++++++ .../printing-variables-in-php.md | 72 ++++++++++++ 36 files changed, 1901 insertions(+) create mode 100644 php/README.md create mode 100644 php/php-core/README.md create mode 100644 php/php-core/control-flow-i-php/README.md create mode 100644 php/php-core/control-flow-i-php/comparison-operators-php.md create mode 100644 php/php-core/control-flow-i-php/if-else-statements-php.md create mode 100644 php/php-core/control-flow-i-php/if-statements-php.md create mode 100644 php/php-core/control-flow-i-php/nested-if-else-statements-php.md create mode 100644 php/php-core/intro-to-php/README.md create mode 100644 php/php-core/intro-to-php/first-program-php.md create mode 100644 php/php-core/intro-to-php/installing-php-locally.md create mode 100644 php/php-core/intro-to-php/what-is-php.md create mode 100644 php/php-core/intro-to-php/why-learn-php.md create mode 100644 php/php-core/logical-operators-php/README.md create mode 100644 php/php-core/logical-operators-php/and-php.md create mode 100644 php/php-core/logical-operators-php/and-precedence-php.md create mode 100644 php/php-core/logical-operators-php/not-php.md create mode 100644 php/php-core/logical-operators-php/or-php.md create mode 100644 php/php-core/logical-operators-php/what-are-logical-operators-php.md create mode 100644 php/php-core/logical-operators-php/xor-php.md create mode 100644 php/php-core/looping-php/README.md create mode 100644 php/php-core/looping-php/do-while-loops-php.md create mode 100644 php/php-core/looping-php/for-each-loops-php.md create mode 100644 php/php-core/looping-php/for-loops-php.md create mode 100644 php/php-core/looping-php/what-are-loops-php.md create mode 100644 php/php-core/looping-php/while-loops-php.md create mode 100644 php/php-core/more-data-types-php/README.md create mode 100644 php/php-core/more-data-types-php/array-functions-php.md create mode 100644 php/php-core/more-data-types-php/arrays-php.md create mode 100644 php/php-core/variables-and-data-types-php/README.md create mode 100644 php/php-core/variables-and-data-types-php/assignment-operators-php.md create mode 100644 php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md create mode 100644 php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md create mode 100644 php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md create mode 100644 php/php-core/variables-and-data-types-php/basic-data-types-php.md create mode 100644 php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md create mode 100644 php/php-core/variables-and-data-types-php/printing-variables-in-php.md diff --git a/php/README.md b/php/README.md new file mode 100644 index 0000000000..90b9b6e349 --- /dev/null +++ b/php/README.md @@ -0,0 +1,12 @@ +name: PHP + +description: + +color: + +icon: + +language: + +availableAspects: + - introduction \ No newline at end of file diff --git a/php/php-core/README.md b/php/php-core/README.md new file mode 100644 index 0000000000..afc11aa970 --- /dev/null +++ b/php/php-core/README.md @@ -0,0 +1,14 @@ +name: PHP Core + +description: + +core: true + +sections: + '0': + - intro-to-php + - variables-and-data-types-php + - control-flow-i-php + - logical-operators-php + - looping-php + - more-data-types-php \ No newline at end of file diff --git a/php/php-core/control-flow-i-php/README.md b/php/php-core/control-flow-i-php/README.md new file mode 100644 index 0000000000..a1e97bcf27 --- /dev/null +++ b/php/php-core/control-flow-i-php/README.md @@ -0,0 +1,12 @@ +name: Control Flow I + +description: Explore PHP's fundamental control flow. + +insights: + - if-statements-php + - comparison-operators-php + - if-else-statements-php + - nested-if-else-php + +aspects: + - introduction diff --git a/php/php-core/control-flow-i-php/comparison-operators-php.md b/php/php-core/control-flow-i-php/comparison-operators-php.md new file mode 100644 index 0000000000..d64c379cc4 --- /dev/null +++ b/php/php-core/control-flow-i-php/comparison-operators-php.md @@ -0,0 +1,99 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# Comparison Operators + +--- + +## Content + +Comparison operators can be used to compare various types of data, including numbers, strings, and booleans. + +PHP's comparison operators are flexible and can handle different data types appropriately. + +Here's a table of comparison operators you can use: + +| Operator | Name | +|:--------:|:---------------------------:| +| == | is equal to | +| != | is not equal to | +| < | is less than | +| <= | is less than or equal to | +| > | is greater than | +| >= | is greater than or equal to | + +```php +$num = 1; +if ($num == 1) { // true + echo "num is $num"; +} +// num is 1 + +if ($num >= 1) { // true + echo "$num is greater than or equal to 1"; +} +// 1 is greater than or equal to 1 + +if ($num < 5) { // true + echo "$num is less than 5"; +} +// 1 is less than 5 + +if ($num != 2) { // true + echo "$num doesn't equal 2"; +} +// 1 doesn't equal 2 + +// ... +``` + + +--- + +## Practice + +Finish the code to output "$num is greater than or equal to 3" if the condition evaluates to + +```php +??? = 5; +if ($num ??? 3) { + echo "$??? is greater than or equal to 3"; +} +``` + +- $num +- >= +- num +- 5 + + +--- + +## Revision + +Finish the code to output "$num is greater than or equal to 3" + +```php +??? = 5; +if ($num ??? 3) { + echo "$??? is greater than or equal to 3"; +} +``` + +- $num +- >= +- num +- 5 \ No newline at end of file diff --git a/php/php-core/control-flow-i-php/if-else-statements-php.md b/php/php-core/control-flow-i-php/if-else-statements-php.md new file mode 100644 index 0000000000..f0ecaacd34 --- /dev/null +++ b/php/php-core/control-flow-i-php/if-else-statements-php.md @@ -0,0 +1,70 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# If else Statements + +--- + +## Content + +We can extend the `if` statement to include an `else` clause, which will be executed if the condition is not met. + +```php +$num = 1; +if ($num == 0) { // false + echo "num equals 0"; +} else { // will execute if condition is false + echo "num doesn't equal 0"; +} + +// num doesn't equal 0 +``` + +--- + +## Practice + +What does the following code snippet print? + +```php +$x = 4; +if ($x <= 3) { + echo 'x is smaller'; +} else { + echo 'x is larger'; +} +``` + +- x is larger +- x is smaller + +--- + +## Revision + +What does the following code snippet print? + +```php +$x = 13; +if ($x == 13) { + echo 'true'; +} else { + echo 'false'; +} +``` + +- true +- false diff --git a/php/php-core/control-flow-i-php/if-statements-php.md b/php/php-core/control-flow-i-php/if-statements-php.md new file mode 100644 index 0000000000..62e89f7c21 --- /dev/null +++ b/php/php-core/control-flow-i-php/if-statements-php.md @@ -0,0 +1,76 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# If Statements + +--- + +## Content + +The flow of a PHP program depends on the order in which individual commands are executed. Control flow statements like if...else allow us to manage the order using conditions. + +```php +if (condition) { + // execute this code +} +``` + +The script will only execute the code if the condition has been met. + +```php +$num = 5; +if ($num > 0) { + echo "$num is a positive number"; +} +``` + +The above would output: +```plain-text +5 is a positive number +``` + +If the condition `$num > 0` evaluates to `false`, this code would not output anything. + +--- +## Practice + +What does the following code snippet print? + +```php +$num = 5; +if ($num > 0) { + echo "$num is a positive number"; +} +``` + +- 5 is a positive number +- nothing + +--- + +## Revision + +What does the following code snippet print? + +```php +$num = 0; +if ($num > 0) { + echo "num is 0"; +} +``` + +- nothing +- num is 0 diff --git a/php/php-core/control-flow-i-php/nested-if-else-statements-php.md b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md new file mode 100644 index 0000000000..f0d2dae0da --- /dev/null +++ b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md @@ -0,0 +1,109 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + - type-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# Nested if else Statements + +--- + +## Content + +In PHP, we can have an `if-else` statement inside another `if-else` statement. This is called nesting. + +Nested `if-else` statements can be used to perform complex decision making. + +Here's a basic example: +```php +$age = 20; + +if($age >= 18){ + if($age <= 60){ + echo "You are an adult."; + } + else{ + echo "You are a senior."; + } +} +else{ + echo "You are not an adult."; +} +``` + +In this example, the program first checks if `age` is greater than or equal to 18. + +If true, it enters the next level of the `if` statement and checks if `age` is less than or equal to 60. + +If true, it outputs `"You are an adult."` + +If false, it outputs `"You are a senior."` + +If the first `if` condition is false, it outputs `"You are not an adult."`. + + + +--- + +## Practice + +What is the output of the following code? + +```php +$age = 70; + +if($age >= 18){ + if($age <= 60){ + echo "You are an adult."; + } + else{ + echo "You are a senior."; + } +} +else{ + echo "You are not an adult."; +} +// Output: ??? +``` + +- You are a senior. +- You are not an adult. +- You are an adult. + +--- + +## Revision + +What is the output of the following code? + +```php +$age = 15; + +if($age >= 18){ + if($age <= 60){ + echo "You are an adult."; + } + else{ + echo "You are a senior."; + } +} +else{ + echo "You are not an adult."; +} +// Output: ??? +``` + +- You are not an adult. +- You are a senior. +- You are an adult. \ No newline at end of file diff --git a/php/php-core/intro-to-php/README.md b/php/php-core/intro-to-php/README.md new file mode 100644 index 0000000000..9e613cf941 --- /dev/null +++ b/php/php-core/intro-to-php/README.md @@ -0,0 +1,12 @@ +name: PHP Intro + +description: + +insights: + - what-is-php + - why-learn-php + - installing-php-locally + - first-program-php + +aspects: + - workout \ No newline at end of file diff --git a/php/php-core/intro-to-php/first-program-php.md b/php/php-core/intro-to-php/first-program-php.md new file mode 100644 index 0000000000..d9f53ea703 --- /dev/null +++ b/php/php-core/intro-to-php/first-program-php.md @@ -0,0 +1,72 @@ +--- +author: Stefan-Stojanovic + +type: normal + +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone + +--- + +# Let's Create Our First Program! + +--- + +## Content + +Ready for some code? + +It's time to create our first program! Let's create a `"Hello, World!"` one. + +`"Hello, World!"` is a simple program that prints the text `"Hello, World!"` to the screen. It is often used as a starting point when learning a new programming language. + +In **PHP**, you can print text to the screen using the `echo` method. Here is an example: +```php + + +// Hello, World! +``` + +To run the program, you can save it to a script file with the `.cpp` extension, for instance `hello.cpp` and run it using this command: +```php +php hello.php +``` + +You should see the text "Hello, World!" printed to the screen. + +--- +## Practice + +Which function is used to print text to the screen in **PHP**? + +```php +???("Hello, World!") +``` + +- `echo` +- `print` +- `printout` +- `display` + +--- +## Revision + +Which command is used to run a script file called hello.php in **PHP**? + +```php +??? hello.php +``` + +- `php` +- `run` +- `execute` +- `eval` diff --git a/php/php-core/intro-to-php/installing-php-locally.md b/php/php-core/intro-to-php/installing-php-locally.md new file mode 100644 index 0000000000..0eb0a01e25 --- /dev/null +++ b/php/php-core/intro-to-php/installing-php-locally.md @@ -0,0 +1,36 @@ +--- +author: Stefan-Stojanovic +type: normal +category: tip + +--- + +# Installing PHP Locally + + +--- + +## Content + +To install **PHP**, you can follow these steps: + +### Windows + +Download the VC15 x64 Non Thread Safe version from the official [PHP website](https://windows.php.net/download/). Then, extract the zip file to a directory. + +### Linux + +**PHP** can be installed via the package manager. For example, on Ubuntu, you would use this command: +```bash +sudo apt install php. +``` + +### MacOs + +On macOS, **PHP** is preinstalled, but you can use Homebrew to install a more recent version. + +```bash +brew install php +``` + +Once the installation is complete, you can start using **PHP** by writing scripts and running them with the **PHP** command-line interface or with a web server that supports **PHP** (like Apache or Nginx). \ No newline at end of file diff --git a/php/php-core/intro-to-php/what-is-php.md b/php/php-core/intro-to-php/what-is-php.md new file mode 100644 index 0000000000..891df98f62 --- /dev/null +++ b/php/php-core/intro-to-php/what-is-php.md @@ -0,0 +1,42 @@ +--- +author: Stefan-Stojanovic + +type: normal + +category: must-know + +--- + +# What is PHP? + +--- + +## Content + +**PHP** is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. **PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser. + +A unique feature of **PHP** is that it can be embedded directly within HTML, which simplifies the creation of dynamic web pages. + +Here's an example of **PHP** embedded in HTML: +```php + + + + +

Welcome to My Home Page

+ + + + + +``` + +> Do not worry if you do not understand the code, this is just an example to get you confortable with the syntax. We will dive deeper into it later on. + + +> 💬 Why are you interested in **PHP**? +> +> Leave a comment or view some of the other comments for inspiration before moving on. + diff --git a/php/php-core/intro-to-php/why-learn-php.md b/php/php-core/intro-to-php/why-learn-php.md new file mode 100644 index 0000000000..f88e1ee259 --- /dev/null +++ b/php/php-core/intro-to-php/why-learn-php.md @@ -0,0 +1,23 @@ +--- +author: Stefan-Stojanovic + +type: normal + +category: must-know + +--- + +# Why It's Good to Learn PHP? + +--- + +## Content + +There are several reasons why learning **PHP** can be beneficial: + +- **PHP** has a straightforward learning curve, making it an excellent choice for beginners looking to step into back-end web development. +- It is fully embedded within **HTML**, making it a great language for creating dynamic web pages. +- **PHP** has extensive online documentation and a large community, making it easier to find help and resources. +- It is widely used, and skills in **PHP** are often sought after for web development roles. + +Overall, learning **PHP** can open up opportunities in web development and help you build dynamic and interactive web applications. \ No newline at end of file diff --git a/php/php-core/logical-operators-php/README.md b/php/php-core/logical-operators-php/README.md new file mode 100644 index 0000000000..db86a57e81 --- /dev/null +++ b/php/php-core/logical-operators-php/README.md @@ -0,0 +1,14 @@ +name: Logical Operators + +description: + +insights: + - what-are-logical-operators-php + - and-php + - and-precedence-php + - or-php + - not-php + - xor-php + +aspects: + - introduction diff --git a/php/php-core/logical-operators-php/and-php.md b/php/php-core/logical-operators-php/and-php.md new file mode 100644 index 0000000000..529d293636 --- /dev/null +++ b/php/php-core/logical-operators-php/and-php.md @@ -0,0 +1,94 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# AND (and, &&) Operators + +--- + +## Content + +The `and` and `&&` operators in **PHP** return true only if both operands are true. Otherwise, they return false. + +Here are some examples: + +```cpp +$a = true; +$b = false; + +if($a && $b) { + echo "Both a and b are true."; +} else { + echo "Either a, b or both are false."; +} +// Output: "Either a or b is false." +``` + +```cpp +$a = true; +$b = false; + +if($a and $b) { + echo "Both a and b are true."; +} else { + echo "Either a, b or both are false."; +} +// Output: "Either a or b is false." +``` + +Note that there is a difference in precedence between `and` and `&&`. We will look at an example in the next insight. + +--- + +## Practice + +Complete the following code so that the output is "Both a and b are true.": + +```cpp +$a = ???; +$b = true; + +if($a ??? $b) { + echo ???; +} else { + echo "Either a or b is false."; +} +// Output: "Both a and b are true." +``` + +- true +- && +- "Both a and b are true." + +--- + +## Revision + +What is the output of the following code? + +```cpp +$a = false; +$b = true; + +if($a && $b) { + echo "Both a and b are true."; +} else { + echo "Either a or b is false."; +} +// Output: ??? +``` + +- "Either a or b is false." +- "Both a and b are true." \ No newline at end of file diff --git a/php/php-core/logical-operators-php/and-precedence-php.md b/php/php-core/logical-operators-php/and-precedence-php.md new file mode 100644 index 0000000000..6defc09942 --- /dev/null +++ b/php/php-core/logical-operators-php/and-precedence-php.md @@ -0,0 +1,106 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +links: + - >- + [PHP documentation](https://www.php.net/manual/en/language.operators.precedence.php){documentation} + +--- + +# (and, &&) Precedence + +--- + +## Content + +The `and` and `&&` operators differ in their precedence. The `&&` operator has a higher precedence. + +Note: This only applies if both are used at the same time. The presedence doesn't matter when only one of them is used. + +Let's look at an example: + +```cpp +$a = true; +$b = false; +$c = true; + +if($a and $b && $c) { + echo "This will not print."; +} else { + echo "This will print."; +} +// Output: "This will print." + +if($a && $b and $c) { + echo "This will not print."; +} else { + echo "This will print."; +} +// Output: "This will not print." +``` + +In the first `if` statement, `$a` and `$b` && `$c` is evaluated like `($a and $b) && $c` due to `&&` having higher precedence. + +So it first evaluates `$a` and `$b` which results in false (since `$b` is false), and then false && `$c` is also false. + +In the second `if` statement, `$a` && `$b` and `$c` is evaluated like `$a && ($b and $c)`. + +So it first evaluates `$b` and `$c` which results in false (since `$b` is false), and then `$a` && false is also false. + +So be careful when mixing `and` and `&&` in the same expression because `&&` has a higher precedence and will be evaluated first. + +To avoid confusion, stick with one type of operator, or use parentheses to make the precedence explicit. + +--- + +## Practice + +Complete the following code so that the output is "Both a and b are true.": + +```cpp +$a = ???; +$b = true; + +if($a ??? $b) { + echo ???; +} else { + echo "Either a or b is false."; +} +// Output: "Both a and b are true." +``` + +- true +- && +- "Both a and b are true." + +--- + +## Revision + +What is the output of the following code? + +```cpp +$a = false; +$b = true; + +if($a && $b) { + echo "Both a and b are true."; +} else { + echo "Either a or b is false."; +} +// Output: ??? +``` + +- "Either a or b is false." +- "Both a and b are true." \ No newline at end of file diff --git a/php/php-core/logical-operators-php/not-php.md b/php/php-core/logical-operators-php/not-php.md new file mode 100644 index 0000000000..b11fe04aae --- /dev/null +++ b/php/php-core/logical-operators-php/not-php.md @@ -0,0 +1,76 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# NOT (!) Operator + +--- + +## Content + +The `!` operator returns the inverse of the operand's boolean value. If the operand is true, it returns false, and vice versa. + +```cpp +bool a = true; + +if(!a) { + printf("a is false.") +} else { + printf("a is true.") +} +// Output: "a is true." +``` + +--- + +## Practice + +Finish the code to output 'a is false'? + +```cpp +$a = ???; + +if(???) { + echo "a is false"; +} else { + echo "a is true"; +} +// Output: a is false +``` + +- false +- `!$a` +- `!$b` +- true + +--- + +## Revision + +What is the output of the following code? + +```cpp +$a = true; + +if(!$a) { + echo "a is false"; +} else { + echo "a is true"; +} +// Output: a is ??? +``` + +- true +- false \ No newline at end of file diff --git a/php/php-core/logical-operators-php/or-php.md b/php/php-core/logical-operators-php/or-php.md new file mode 100644 index 0000000000..fdc78b30c8 --- /dev/null +++ b/php/php-core/logical-operators-php/or-php.md @@ -0,0 +1,93 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# OR (||, or) operator + +--- + +## Content + +The `or` and `||` operators in PHP return true if at least one of the operands is true. If both operands are false, they return false. + +Here are some examples: +```php +$a = true; +$b = false; + +if($a || $b) { + echo "At least one of a or b is true."; +} else { + echo "Both a and b are false."; +} +// Output: "At least one of a or b is true." +``` + +```php +$a = true; +$b = false; + +if($a or $b) { + echo "At least one of a or b is true."; +} else { + echo "Both a and b are false."; +} +// Output: "At least one of a or b is true." +``` + +Just like the `and` and `&&` operators, `or` and `||` have different precedence. The `||` operator has a higher precedence than `or`. + +--- + +## Practice + +What is the output of the following code? + +```cpp +$a = false; +$b = false; + +if($a || $b) { + echo "At least one of a or b is true."; +} else { + echo "Both a and b are false."; +} +// Output: ??? + +``` + +- "Either a, b or both a and b are true." +- "Both a and b is false." + +--- + +## Revision + +What is the output of the following code? + +```cpp +$a = true; +$b = false; + +if($a || $b) { + echo "At least one of a or b is true."; +} else { + echo "Both a and b are false."; +} +// Output: ??? +``` + +- "Both a and b is false." +- "Either a, b or both a and b are true." \ No newline at end of file diff --git a/php/php-core/logical-operators-php/what-are-logical-operators-php.md b/php/php-core/logical-operators-php/what-are-logical-operators-php.md new file mode 100644 index 0000000000..366d952e9a --- /dev/null +++ b/php/php-core/logical-operators-php/what-are-logical-operators-php.md @@ -0,0 +1,30 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know + +--- + +# Logical Operators + +--- + +## Content + +Logical operators in PHP are used to perform logical operations on the operands. + +They mainly involve boolean values and they return a boolean value as a result. + +The logical operators provided by PHP include: + +| Operator | Name | +|:--------:|:----:| +| and | AND | +| or | OR | +| xor | XOR | +| ! | NOT | +| && | AND | +| || | OR | + diff --git a/php/php-core/logical-operators-php/xor-php.md b/php/php-core/logical-operators-php/xor-php.md new file mode 100644 index 0000000000..6cabb292cd --- /dev/null +++ b/php/php-core/logical-operators-php/xor-php.md @@ -0,0 +1,78 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# XOR Operator + +--- + +## Content + +In PHP, the `xor` operator is a logical operator that returns true if exactly one of the two operands (conditions) is true, otherwise it returns false. + +Here is an example: +```php +$a = true; +$b = false; + +if($a xor $b) { + echo "Exactly one of a or b is true."; +} else { + echo "Both a and b are either true or false."; +} +// Output: "Exactly one of a or b is true." +``` + +--- + +## Practice + +What is the output of the following code? + +```cpp +$a = true; +$b = true; + +if($a xor $b) { + echo "Exactly one of a or b is true"; +} else { + echo "Both a and b are either true or false"; +} +// Output: ??? +``` + +- Exactly one of a or b is true +- Both a and b are either true or false + +--- + +## Revision + +What is the output of the following code? + +```cpp +$a = false; +$b = false; + +if($a xor $b) { + echo "Exactly one of a or b is true"; +} else { + echo "Both a and b are either true or false"; +} +// Output: ??? +``` + +- Exactly one of a or b is true +- Both a and b are either true or false \ No newline at end of file diff --git a/php/php-core/looping-php/README.md b/php/php-core/looping-php/README.md new file mode 100644 index 0000000000..5f60d2f1b6 --- /dev/null +++ b/php/php-core/looping-php/README.md @@ -0,0 +1,12 @@ +name: Looping +description: How to loop +insights: + - what-are-loops-php + - for-loops-php + - while-loops-php + - do-while-loops-php + - for-each-loops-php + +aspects: + - introduction + diff --git a/php/php-core/looping-php/do-while-loops-php.md b/php/php-core/looping-php/do-while-loops-php.md new file mode 100644 index 0000000000..ab5a5c1b22 --- /dev/null +++ b/php/php-core/looping-php/do-while-loops-php.md @@ -0,0 +1,72 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# do...while Loops + +--- + +## Content + +The `do...while` loop will execute the block of code once, and then repeat the loop as long as a specified condition is true. + +```php +$i = 0; +do { + echo $i; + $i++; +} while ($i < 3); +// Output: 012 +``` + +In the example, the loop will start at 0 `$i = 0`, continue as long as `$i` is less than 3 `$i < 3`, and `$i` will increase by 1 each time the loop runs `$i++`. + + + +--- +## Practice + +Fill in the blanks to output the numbers 1 through 5: + +```php +$i = 1; +do { + echo $i; + $i++; +} ??? ($i <= ???); +``` + +- while +- 5 +- do +- for + +--- +## Revision + + +Fill in the blanks to output the numbers 5 through 10: + +```php +$i = ???; +do { + echo $i; + $i++; +} ??? ($i <= ???); +``` + +- 5 +- while +- 10 +- do +- for diff --git a/php/php-core/looping-php/for-each-loops-php.md b/php/php-core/looping-php/for-each-loops-php.md new file mode 100644 index 0000000000..80875017d1 --- /dev/null +++ b/php/php-core/looping-php/for-each-loops-php.md @@ -0,0 +1,84 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# foreach Loop + +--- + +## Content + +A `foreach` loop is used to iterate over arrays. + +Here's an example: +```php +$array = array(1, 2, 3, 4, 5); + +foreach ($array as $value) { + echo $value; +} +// Output: 12345 +``` + +In this case, the `foreach` loop is iterating over each value in the `$array`. For each iteration, `$value` is assigned the current item's value, and the code inside the loop is executed. + +It's also possible to access both the key and the value of the current item: +```php +$array = array("a" => "Apple", "b" => "Banana", "c" => "Cherry"); + +foreach ($array as $key => $value) { + echo "$key: $value\n"; +} +// Output: +// a: Apple +// b: Banana +// c: Cherry +``` + +--- + +## Practice + +What is the output of the following code? + +```php +$array = array(10, 20, 30); + +foreach ($array as $value) { + echo $value; +} +// Output: ??? +``` + +- 102030 +- 1020 +- 123 +- 302010 + +--- +## Revision + +Fill in the blanks to output the values of the array: +```php +$array = array("Red", "Green", "Blue"); + +foreach ($array as $???) { + echo $value; +} +// Output: RedGreenBlue +``` + +- value +- key +- index +- part \ No newline at end of file diff --git a/php/php-core/looping-php/for-loops-php.md b/php/php-core/looping-php/for-loops-php.md new file mode 100644 index 0000000000..08028d4538 --- /dev/null +++ b/php/php-core/looping-php/for-loops-php.md @@ -0,0 +1,65 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# for loops + +--- +## Content + +In PHP, the `for` loop is used when you know in advance how many times the script should run. It consists of three parts: the initialization, the condition, and the increment/decrement. + +Example: +```php +for($i = 0; $i < 5; $i++){ + echo $i; +} +// Output: 01234 +``` + +In the example, the loop starts at 0 `$i = 0`, and continues as long as `$i` is less than 5 `$i < 5`, and `$i` will increase by 1 each time the loop runs `$i++`. + + +--- +## Practice + +Fill in the blank to output the numbers 1 through 5: + +```php +for($i = 1; $i <= ???; $i++){ + echo $i; +} +``` + +- 5 +- 4 +- 3 +- 6 + +--- +## Revision + +What is the output of the following code? + +```php +for($i = 1; $i <= 3; $i++){ + echo $i; +} + +// Output: ??? +``` + +- 123 +- 0123 +- 012 +- 23 \ No newline at end of file diff --git a/php/php-core/looping-php/what-are-loops-php.md b/php/php-core/looping-php/what-are-loops-php.md new file mode 100644 index 0000000000..09cc727148 --- /dev/null +++ b/php/php-core/looping-php/what-are-loops-php.md @@ -0,0 +1,20 @@ +--- +author: Stefan-Stojanovic + +type: normal + +category: must-know + +--- + +# What Are Loops? + +--- + +## Content + +In **PHP**, a loop is a programming structure that repeats a sequence of instructions until a specific condition is met. **PHP** supports several types of loops: +- `for` +- `while` +- `do-while` +- `foreach` \ No newline at end of file diff --git a/php/php-core/looping-php/while-loops-php.md b/php/php-core/looping-php/while-loops-php.md new file mode 100644 index 0000000000..0e5710c764 --- /dev/null +++ b/php/php-core/looping-php/while-loops-php.md @@ -0,0 +1,73 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# while Loops + + +--- + +## Content + +The `while` loop continues to execute a block of code as long as a specified condition is `true`. + +Example: +```php +$i = 0; +while($i < 5){ + echo $i; + $i++; +} +// Output: 01234 +``` + +In the example above, the loop will start at 0 `$i = 0`, continue as long as `$i` is less than 5 `$i < 5`, and `$i` will increase by 1 each time the loop runs `$i++`. + + +--- +## Practice + +Fill in the blank to output the numbers 1 to 10: + +```php +$i = 1; +while($i <= ???){ + echo $i; + $i++; +} +``` + +- 10 +- 11 +- 5 +- 6 + +--- +## Revision + +What is the output of the following code? + +```php +$i = 1; +while($i <= 3){ + echo $i; + $i++; +} + +// Output: ??? +``` + +- 123 +- 23 +- 1234 +- 0123 diff --git a/php/php-core/more-data-types-php/README.md b/php/php-core/more-data-types-php/README.md new file mode 100644 index 0000000000..6d662b9e79 --- /dev/null +++ b/php/php-core/more-data-types-php/README.md @@ -0,0 +1,12 @@ +name: More Data Types + +description: + +insights: + + + - arrays-php + - array-functions-php + +aspects: + - introduction diff --git a/php/php-core/more-data-types-php/array-functions-php.md b/php/php-core/more-data-types-php/array-functions-php.md new file mode 100644 index 0000000000..7718f6b9ce --- /dev/null +++ b/php/php-core/more-data-types-php/array-functions-php.md @@ -0,0 +1,45 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know + +--- + +# Array Functions + +--- + +## Content + +**PHP** provides a large number of built-in functions for manipulating arrays: + +- `count()`: returns the number of elements in an array. +- `sort()`: sorts the elements of an array in ascending order. +- `rsort()`: sorts the elements of an array in descending order. +- `array_push()`: pushes one or more elements onto the end of an array. +- `array_pop()`: pops and returns the last value of the array, shortening the array by one element. + + +```php +$numbers = array(2, 3, 1); + +echo "Count: " . count($numbers) . "\n"; +// Output: Count: 3 + +sort($numbers); +echo "Sorted: " . implode(", ", $numbers) . "\n"; +// Output: Sorted: 1, 2, 3 + +rsort($numbers); +echo "Reversed: " . implode(", ", $numbers) . "\n"; +// Output: Reversed: 3, 2, 1 + +// Add more elements +array_push($numbers, 4, 5, 6); + +// Remove the last element of the array +$lastElement = array_pop($numbers); +``` + diff --git a/php/php-core/more-data-types-php/arrays-php.md b/php/php-core/more-data-types-php/arrays-php.md new file mode 100644 index 0000000000..57eef7e868 --- /dev/null +++ b/php/php-core/more-data-types-php/arrays-php.md @@ -0,0 +1,97 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# Arrays + +--- + +## Content + +An array is a special variable that can hold multiple values at a time. + +Here's how you define an array that holds 5 integers in PHP: +```php +$numbers = array(1, 2, 3, 4, 5); +``` + +To access an element in the array, use the index of that element (keep in mind that indexing starts at 0): + +```php +echo $numbers[0]; +// Output: 1 +``` + +Arrays in PHP can also be associative, where you can assign keys to the values: +```php +$numbers = array( + 'one' => 1, + 'two' => 2, + 'three' => 3, + 'four' => 4, + 'five' => 5 +); +``` + +For outputting the contents of the whole array, we can use the `print_r()` function: +```php +print_r($numbers); +``` + +Which gives us this output: +```php +Array +( + [one] => 1 + [two] => 2 + [three] => 3 + [four] => 4 + [five] => 5 +) +``` + + + +--- + +## Practice + +Fill in the code to create an array of integers called `nums` that hold numbers from 1 through 5: + +```csharp +??? = ???(1, 2, 3, 4, 5); +``` + + +- $nums +- array +- $arr +- nums + +--- + +## Revision + +Fill in the code to output the number 7 from the `numbers` array using its index: +```csharp +$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +echo $numbers[???]; +// Output: 7 +``` + +- 6 +- 7 +- 0 +- 1 \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/README.md b/php/php-core/variables-and-data-types-php/README.md new file mode 100644 index 0000000000..5475a8b865 --- /dev/null +++ b/php/php-core/variables-and-data-types-php/README.md @@ -0,0 +1,16 @@ +name: Variables & Data Types + +description: Learn about variables and basic data types in PHP. + +insights: + - creating-and-storing-variables-in-php + - assignment-operators-php + - basic-data-types-php + - basic-data-types-php-ii + - basic-data-types-php-iii + - basic-data-types-php-iv + - printing-variables-in-php + +aspects: + - workout + - deep \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/assignment-operators-php.md b/php/php-core/variables-and-data-types-php/assignment-operators-php.md new file mode 100644 index 0000000000..8ea94d9052 --- /dev/null +++ b/php/php-core/variables-and-data-types-php/assignment-operators-php.md @@ -0,0 +1,70 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# Assignment Operators in PHP + +--- + +## Content + +In **PHP**, assignment operators are used to assign values to variables. + +The most common assignment operator is the `=` operator, which is used to assign a value to a variable: +```php +$x = 7; +$y = 13; + +echo $x; +// Outputs: 7 +echo $y; +// Outputs: 13 +``` + +**PHP** also includes compound assignment operators such as `+=`, `-=`, `*=`, and `/=`. These operators modify the value of the variable: +```php +// equivalent to $x = $x + 5 +$x += 5; +echo $x; +// Outputs: 12 + +// equivalent to $y = $y * 2 +$y *= 2; +echo $y; +// Outputs: 26 +``` + +--- +## Practice + +Which operator is used to assign a value to a variable in **PHP**? + +- `=` +- `==` +- `->` +- `>` + +--- +## Revision + +Which of these variables uses the recommended way of assigning values in **PHP**? + +```plain-text +x = 2; +$y = 10; +``` + +??? + +- y +- x diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md b/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md new file mode 100644 index 0000000000..ef4e630a76 --- /dev/null +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md @@ -0,0 +1,29 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know + +--- + +# Basic Data Types (integer, float) + +--- + +## Content + +Integers are whole numbers, such as 1, 2, 3, 99, 5555. +```php +$number = 10; +echo $number; +// 10 +``` + +### float +--- + +Floating-point numbers (also refered to as **double**), are numbers that contain a decimal point. +```php +$number = 10.5; +echo $number; +// 10.5 +``` \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md b/php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md new file mode 100644 index 0000000000..b456427826 --- /dev/null +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md @@ -0,0 +1,20 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know + +--- + +# Basic Data Types (string) + +--- + +## Content + +The `string` type represents a sequence of characters, such as "hello", "Enki", and so on. + +```php +$greeting = "Hello, world!"; +echo $greeting; +// Hello, world! +``` diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md b/php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md new file mode 100644 index 0000000000..4a23c3d061 --- /dev/null +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md @@ -0,0 +1,19 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know + +--- + +# Basic Data Types (bool) + +--- + +## Content + +Boolean values are either `true` or `false`: +```php +$true = true; +var_dump($true); +// true +``` diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php.md b/php/php-core/variables-and-data-types-php/basic-data-types-php.md new file mode 100644 index 0000000000..70eedc036e --- /dev/null +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php.md @@ -0,0 +1,42 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know + +--- + +# Basic Data Types in PHP + +--- + +## Content + +In PHP, variable are loosely typed, meaning that they are converted automatically as needed by the context where they are being used. + +However, for better clarity, we can specify the "type" of data that a variable can hold. + +**PHP** supports eight primitive types which can be grouped into three categories: + +### Scalar types +--- + +- `int` for storing integers, like 5, -10, or 3333. +- `float` (or double) for storing floating-point numbers, like 3.14159 or -0.001. +- `string` for storing sequences of characters, like "Hello, world!" or "Enki". +- `bool` for storing Boolean values, i.e., true or false. + +### Compound types +--- + +- `array` for storing multiple values in a single variable. +- `object` for storing instances of classes. + +### Special types +--- + +- resource for storing references to functions and resources external to PHP. +- NULL for a variable with no value. + +**Note:** that PHP is a dynamically typed language and type declaration is not required. + +> We will cover the scalar types in this workout. \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md b/php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md new file mode 100644 index 0000000000..956b8a76fb --- /dev/null +++ b/php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md @@ -0,0 +1,85 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + - type-in-the-gap + context: standalone + +--- + +# Creating and Storing Variables + +--- + +## Content + +Variables are crucial in programming. They are named locations in memory that store a value, which can be later retrieved and used. They allow us to store and manipulate data in a program. + +In **PHP**, variables are declared with a dollar sign `$` and do not require a type to be specified: +```csharp +$x = 5; +$y = 10.0; +``` + +To print the value of a variable we use `echo`: +```csharp +echo $x; +// Outputs: 5 +echo $y; +// Outputs: 10.0 +``` + +You can also create variables using other variables: +```csharp +$z = $x + $y; +echo $z; +// Outputs: 15.0 +``` + +Note that variables are case-sensitive. These are three different variables: +```php +$number = 1 +$nUmber = 1 +$numbeR = 1 +``` + +--- +## Practice + +Which of the following is the correct way to create a variable in **PHP**? + +??? + +- `$x = 5;` +- `x = 5;` +- `@y = 10.0;` +- `*z = 3;` + + +--- +## Revision + +Finish the code to create a new variable called `c` by summing the values of the `a` and `b` variables. Print the new variable. +```cpp +$a = 3; +$b = 7; + +??? = $a ??? $b; + +??? $c; +// 10 +``` + +- `$c` +- `+` +- `echo` +- `-` +- `plus` +- `print` diff --git a/php/php-core/variables-and-data-types-php/printing-variables-in-php.md b/php/php-core/variables-and-data-types-php/printing-variables-in-php.md new file mode 100644 index 0000000000..7cae3ea0fd --- /dev/null +++ b/php/php-core/variables-and-data-types-php/printing-variables-in-php.md @@ -0,0 +1,72 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone + +--- + +# Printing + +--- + +## Content + +In PHP, you can use the `echo` language construct to output messages: +```php +echo "Hello, world!"; +``` + +If you want to print[1] a message and move to a new line, you can use the newline character `\n`. + +**Note** that the newline character only works in double-quoted strings: + +```php +echo "Hello, world!\n"; +``` + +To print the type of variable, we can use `var_dumb`: +```php +$name = "Stefan"; +var_dump($name); + +// type of variable and its value +// string(6) "Stefan" +``` + + +--- +## Practice + +Print a message to the console without adding a newline character after the message: +```php +??? "Hello, world!" +``` + +- `echo` +- `output` + +--- + +## Revision + +Print a message to the console and move to a new line: +```php +echo ??? +``` + +- `"Hello, world!\n"` +- `'Hello, world!\n'` + +--- +## Footnotes + +[1: Printing] +Printing messages in **PHP** is useful for debugging and for communicating information to the user. From 4a5b1216a27b92687fbe27a8a6668e7739453fd4 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 11 Oct 2023 10:13:53 -0400 Subject: [PATCH 02/22] FIxed configs --- php/README.md | 8 +++----- php/php-core/intro-to-php/README.md | 2 +- php/php-core/logical-operators-php/README.md | 2 +- php/php-core/more-data-types-php/README.md | 4 +--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/php/README.md b/php/README.md index 90b9b6e349..60d8442492 100644 --- a/php/README.md +++ b/php/README.md @@ -1,12 +1,10 @@ name: PHP -description: +description: An efficient, powerful, low-level language -color: +color: A6D8FF -icon: - -language: +icon: https://img.enkipro.com/6fc730e946778fd1474fb41ea0a91a7a.png availableAspects: - introduction \ No newline at end of file diff --git a/php/php-core/intro-to-php/README.md b/php/php-core/intro-to-php/README.md index 9e613cf941..69ab07173a 100644 --- a/php/php-core/intro-to-php/README.md +++ b/php/php-core/intro-to-php/README.md @@ -1,6 +1,6 @@ name: PHP Intro -description: +description: What is PHP? insights: - what-is-php diff --git a/php/php-core/logical-operators-php/README.md b/php/php-core/logical-operators-php/README.md index db86a57e81..23cc12e1bd 100644 --- a/php/php-core/logical-operators-php/README.md +++ b/php/php-core/logical-operators-php/README.md @@ -1,6 +1,6 @@ name: Logical Operators -description: +description: Learn Boolean Algebra in PHP insights: - what-are-logical-operators-php diff --git a/php/php-core/more-data-types-php/README.md b/php/php-core/more-data-types-php/README.md index 6d662b9e79..cf8c6cf6cf 100644 --- a/php/php-core/more-data-types-php/README.md +++ b/php/php-core/more-data-types-php/README.md @@ -1,10 +1,8 @@ name: More Data Types -description: +description: Compound and Special Data insights: - - - arrays-php - array-functions-php From 71abd3bdf103fc3bb390d7630a35509ab66f539f Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 11 Oct 2023 10:16:27 -0400 Subject: [PATCH 03/22] FIxed configs --- php/php-core/README.md | 2 +- php/php-core/control-flow-i-php/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/php-core/README.md b/php/php-core/README.md index afc11aa970..22a5888a9f 100644 --- a/php/php-core/README.md +++ b/php/php-core/README.md @@ -1,6 +1,6 @@ name: PHP Core -description: +description: Basic Syntax and Functionality core: true diff --git a/php/php-core/control-flow-i-php/README.md b/php/php-core/control-flow-i-php/README.md index a1e97bcf27..7260688c52 100644 --- a/php/php-core/control-flow-i-php/README.md +++ b/php/php-core/control-flow-i-php/README.md @@ -6,7 +6,7 @@ insights: - if-statements-php - comparison-operators-php - if-else-statements-php - - nested-if-else-php + - nested-if-else-statements-php aspects: - introduction From b5ce5a11b1ccdffd9376cffbc53fabe525c90a24 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 11 Oct 2023 12:20:09 -0400 Subject: [PATCH 04/22] Fixed questions --- php/php-core/control-flow-i-php/comparison-operators-php.md | 4 ++-- php/php-core/control-flow-i-php/if-else-statements-php.md | 2 ++ php/php-core/control-flow-i-php/if-statements-php.md | 2 ++ .../assignment-operators-php.md | 4 ++++ .../variables-and-data-types-php/basic-data-types-php-ii.md | 1 - .../variables-and-data-types-php/basic-data-types-php.md | 6 +++--- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/php/php-core/control-flow-i-php/comparison-operators-php.md b/php/php-core/control-flow-i-php/comparison-operators-php.md index d64c379cc4..b8c9506972 100644 --- a/php/php-core/control-flow-i-php/comparison-operators-php.md +++ b/php/php-core/control-flow-i-php/comparison-operators-php.md @@ -75,7 +75,7 @@ if ($num ??? 3) { ``` - $num -- >= +- `>=` - num - 5 @@ -94,6 +94,6 @@ if ($num ??? 3) { ``` - $num -- >= +- `>=` - num - 5 \ No newline at end of file diff --git a/php/php-core/control-flow-i-php/if-else-statements-php.md b/php/php-core/control-flow-i-php/if-else-statements-php.md index f0ecaacd34..c77aa60197 100644 --- a/php/php-core/control-flow-i-php/if-else-statements-php.md +++ b/php/php-core/control-flow-i-php/if-else-statements-php.md @@ -48,6 +48,8 @@ if ($x <= 3) { } ``` +??? + - x is larger - x is smaller diff --git a/php/php-core/control-flow-i-php/if-statements-php.md b/php/php-core/control-flow-i-php/if-statements-php.md index 62e89f7c21..ef69811b9a 100644 --- a/php/php-core/control-flow-i-php/if-statements-php.md +++ b/php/php-core/control-flow-i-php/if-statements-php.md @@ -56,6 +56,8 @@ if ($num > 0) { } ``` +??? + - 5 is a positive number - nothing diff --git a/php/php-core/variables-and-data-types-php/assignment-operators-php.md b/php/php-core/variables-and-data-types-php/assignment-operators-php.md index 8ea94d9052..cd215b4cb6 100644 --- a/php/php-core/variables-and-data-types-php/assignment-operators-php.md +++ b/php/php-core/variables-and-data-types-php/assignment-operators-php.md @@ -10,6 +10,7 @@ revisionQuestion: formats: - fill-in-the-gap context: standalone + --- # Assignment Operators in PHP @@ -32,6 +33,7 @@ echo $y; ``` **PHP** also includes compound assignment operators such as `+=`, `-=`, `*=`, and `/=`. These operators modify the value of the variable: + ```php // equivalent to $x = $x + 5 $x += 5; @@ -49,6 +51,8 @@ echo $y; Which operator is used to assign a value to a variable in **PHP**? +??? + - `=` - `==` - `->` diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md b/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md index ef4e630a76..ec74672d49 100644 --- a/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md @@ -19,7 +19,6 @@ echo $number; ``` ### float ---- Floating-point numbers (also refered to as **double**), are numbers that contain a decimal point. ```php diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php.md b/php/php-core/variables-and-data-types-php/basic-data-types-php.md index 70eedc036e..9e4dd16959 100644 --- a/php/php-core/variables-and-data-types-php/basic-data-types-php.md +++ b/php/php-core/variables-and-data-types-php/basic-data-types-php.md @@ -18,7 +18,7 @@ However, for better clarity, we can specify the "type" of data that a variable c **PHP** supports eight primitive types which can be grouped into three categories: ### Scalar types ---- + - `int` for storing integers, like 5, -10, or 3333. - `float` (or double) for storing floating-point numbers, like 3.14159 or -0.001. @@ -26,13 +26,13 @@ However, for better clarity, we can specify the "type" of data that a variable c - `bool` for storing Boolean values, i.e., true or false. ### Compound types ---- + - `array` for storing multiple values in a single variable. - `object` for storing instances of classes. ### Special types ---- + - resource for storing references to functions and resources external to PHP. - NULL for a variable with no value. From af56fb3b67553001da73b92cfce6771f645ba386 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Thu, 12 Oct 2023 13:46:14 -0400 Subject: [PATCH 05/22] Loops split --- .../looping-php/for-each-loops-php-ii.md | 70 +++++++++++++++++++ .../looping-php/for-each-loops-php.md | 59 ---------------- 2 files changed, 70 insertions(+), 59 deletions(-) create mode 100644 php/php-core/looping-php/for-each-loops-php-ii.md diff --git a/php/php-core/looping-php/for-each-loops-php-ii.md b/php/php-core/looping-php/for-each-loops-php-ii.md new file mode 100644 index 0000000000..a4a769239a --- /dev/null +++ b/php/php-core/looping-php/for-each-loops-php-ii.md @@ -0,0 +1,70 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone +revisionQuestion: + formats: + - fill-in-the-gap + context: standalone +--- + +# foreach Loop + +--- + +## Content + +It's also possible to access both the key and the value of the current item: +```php +$array = array("a" => "Apple", "b" => "Banana", "c" => "Cherry"); + +foreach ($array as $key => $value) { + echo "$key: $value\n"; +} +// Output: +// a: Apple +// b: Banana +// c: Cherry +``` + +--- + +## Practice + +What is the output of the following code? + +```php +$array = array(10, 20, 30); + +foreach ($array as $value) { + echo $value; +} +// Output: ??? +``` + +- 102030 +- 1020 +- 123 +- 302010 + +--- +## Revision + +Fill in the blanks to output the values of the array: +```php +$array = array("Red", "Green", "Blue"); + +foreach ($array as $???) { + echo $value; +} +// Output: RedGreenBlue +``` + +- value +- key +- index +- part \ No newline at end of file diff --git a/php/php-core/looping-php/for-each-loops-php.md b/php/php-core/looping-php/for-each-loops-php.md index 80875017d1..8e32122af2 100644 --- a/php/php-core/looping-php/for-each-loops-php.md +++ b/php/php-core/looping-php/for-each-loops-php.md @@ -2,14 +2,6 @@ author: Stefan-Stojanovic type: normal category: must-know -practiceQuestion: - formats: - - fill-in-the-gap - context: standalone -revisionQuestion: - formats: - - fill-in-the-gap - context: standalone --- # foreach Loop @@ -31,54 +23,3 @@ foreach ($array as $value) { ``` In this case, the `foreach` loop is iterating over each value in the `$array`. For each iteration, `$value` is assigned the current item's value, and the code inside the loop is executed. - -It's also possible to access both the key and the value of the current item: -```php -$array = array("a" => "Apple", "b" => "Banana", "c" => "Cherry"); - -foreach ($array as $key => $value) { - echo "$key: $value\n"; -} -// Output: -// a: Apple -// b: Banana -// c: Cherry -``` - ---- - -## Practice - -What is the output of the following code? - -```php -$array = array(10, 20, 30); - -foreach ($array as $value) { - echo $value; -} -// Output: ??? -``` - -- 102030 -- 1020 -- 123 -- 302010 - ---- -## Revision - -Fill in the blanks to output the values of the array: -```php -$array = array("Red", "Green", "Blue"); - -foreach ($array as $???) { - echo $value; -} -// Output: RedGreenBlue -``` - -- value -- key -- index -- part \ No newline at end of file From e59230cf506669b5a765df480767a25fdaa65740 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Thu, 12 Oct 2023 13:48:38 -0400 Subject: [PATCH 06/22] Conig fix --- php/php-core/looping-php/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/php/php-core/looping-php/README.md b/php/php-core/looping-php/README.md index 5f60d2f1b6..aa5f3140e0 100644 --- a/php/php-core/looping-php/README.md +++ b/php/php-core/looping-php/README.md @@ -6,6 +6,7 @@ insights: - while-loops-php - do-while-loops-php - for-each-loops-php + - for-each-loops-php-ii aspects: - introduction From 73e75c94de4eedf9e64cc30bfc0983a37e7176fa Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Thu, 19 Oct 2023 11:32:08 -0400 Subject: [PATCH 07/22] variables and data types --- php/php-core/data-types-php/README.md | 13 +++++++++ .../basic-data-types-php-ii.md | 0 .../basic-data-types-php-iii.md | 21 ++++++++++++++- .../basic-data-types-php-iv.md | 2 +- .../basic-data-types-php.md | 8 ++---- .../variables-and-data-types-php/README.md | 16 ----------- php/php-core/variables-php/README.md | 12 +++++++++ .../assignment-operators-php.md | 15 ++--------- ...eating-and-storing-variables-in-php-ii.md} | 19 ++----------- .../creating-and-storing-variables-in-php.md | 27 +++++++++++++++++++ .../printing-variables-in-php.md | 9 ------- 11 files changed, 79 insertions(+), 63 deletions(-) create mode 100644 php/php-core/data-types-php/README.md rename php/php-core/{variables-and-data-types-php => data-types-php}/basic-data-types-php-ii.md (100%) rename php/php-core/{variables-and-data-types-php => data-types-php}/basic-data-types-php-iii.md (50%) rename php/php-core/{variables-and-data-types-php => data-types-php}/basic-data-types-php-iv.md (93%) rename php/php-core/{variables-and-data-types-php => data-types-php}/basic-data-types-php.md (73%) delete mode 100644 php/php-core/variables-and-data-types-php/README.md create mode 100644 php/php-core/variables-php/README.md rename php/php-core/{variables-and-data-types-php => variables-php}/assignment-operators-php.md (68%) rename php/php-core/{variables-and-data-types-php/creating-and-storing-variables-in-php.md => variables-php/creating-and-storing-variables-in-php-ii.md} (64%) create mode 100644 php/php-core/variables-php/creating-and-storing-variables-in-php.md rename php/php-core/{variables-and-data-types-php => variables-php}/printing-variables-in-php.md (87%) diff --git a/php/php-core/data-types-php/README.md b/php/php-core/data-types-php/README.md new file mode 100644 index 0000000000..122d97ac12 --- /dev/null +++ b/php/php-core/data-types-php/README.md @@ -0,0 +1,13 @@ +name: Data Types + +description: Learn about basic data types in PHP. + +insights: + - basic-data-types-php + - basic-data-types-php-ii + - basic-data-types-php-iii + - basic-data-types-php-iv + +aspects: + - workout + - deep \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md b/php/php-core/data-types-php/basic-data-types-php-ii.md similarity index 100% rename from php/php-core/variables-and-data-types-php/basic-data-types-php-ii.md rename to php/php-core/data-types-php/basic-data-types-php-ii.md diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md b/php/php-core/data-types-php/basic-data-types-php-iii.md similarity index 50% rename from php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md rename to php/php-core/data-types-php/basic-data-types-php-iii.md index b456427826..d99ded8797 100644 --- a/php/php-core/variables-and-data-types-php/basic-data-types-php-iii.md +++ b/php/php-core/data-types-php/basic-data-types-php-iii.md @@ -2,7 +2,10 @@ author: Stefan-Stojanovic type: normal category: must-know - +practiceQuestion: + formats: + - fill-in-the-gap + context: standalone --- # Basic Data Types (string) @@ -18,3 +21,19 @@ $greeting = "Hello, world!"; echo $greeting; // Hello, world! ``` + + +--- +## Practice + +Complete the following code snippet by declaring a `string` variable named `name` and assigning it a value of `"Enki"`. + +```php +??? = "???"; +``` + +- `$name` +- `Enki` +- `name` +- `String` + diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md b/php/php-core/data-types-php/basic-data-types-php-iv.md similarity index 93% rename from php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md rename to php/php-core/data-types-php/basic-data-types-php-iv.md index 4a23c3d061..f7c708c1ab 100644 --- a/php/php-core/variables-and-data-types-php/basic-data-types-php-iv.md +++ b/php/php-core/data-types-php/basic-data-types-php-iv.md @@ -15,5 +15,5 @@ Boolean values are either `true` or `false`: ```php $true = true; var_dump($true); -// true +// bool(true) ``` diff --git a/php/php-core/variables-and-data-types-php/basic-data-types-php.md b/php/php-core/data-types-php/basic-data-types-php.md similarity index 73% rename from php/php-core/variables-and-data-types-php/basic-data-types-php.md rename to php/php-core/data-types-php/basic-data-types-php.md index 9e4dd16959..82aa085d21 100644 --- a/php/php-core/variables-and-data-types-php/basic-data-types-php.md +++ b/php/php-core/data-types-php/basic-data-types-php.md @@ -13,17 +13,15 @@ category: must-know In PHP, variable are loosely typed, meaning that they are converted automatically as needed by the context where they are being used. -However, for better clarity, we can specify the "type" of data that a variable can hold. - **PHP** supports eight primitive types which can be grouped into three categories: ### Scalar types -- `int` for storing integers, like 5, -10, or 3333. +- `int` for storing integers, like `5`, `-10`. - `float` (or double) for storing floating-point numbers, like 3.14159 or -0.001. - `string` for storing sequences of characters, like "Hello, world!" or "Enki". -- `bool` for storing Boolean values, i.e., true or false. +- `bool` for true or false. ### Compound types @@ -37,6 +35,4 @@ However, for better clarity, we can specify the "type" of data that a variable c - resource for storing references to functions and resources external to PHP. - NULL for a variable with no value. -**Note:** that PHP is a dynamically typed language and type declaration is not required. - > We will cover the scalar types in this workout. \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/README.md b/php/php-core/variables-and-data-types-php/README.md deleted file mode 100644 index 5475a8b865..0000000000 --- a/php/php-core/variables-and-data-types-php/README.md +++ /dev/null @@ -1,16 +0,0 @@ -name: Variables & Data Types - -description: Learn about variables and basic data types in PHP. - -insights: - - creating-and-storing-variables-in-php - - assignment-operators-php - - basic-data-types-php - - basic-data-types-php-ii - - basic-data-types-php-iii - - basic-data-types-php-iv - - printing-variables-in-php - -aspects: - - workout - - deep \ No newline at end of file diff --git a/php/php-core/variables-php/README.md b/php/php-core/variables-php/README.md new file mode 100644 index 0000000000..fd37fb6c57 --- /dev/null +++ b/php/php-core/variables-php/README.md @@ -0,0 +1,12 @@ +name: Variables + +description: Learn about variables in PHP. + +insights: + - creating-and-storing-variables-in-php + - assignment-operators-php + - printing-variables-in-php + +aspects: + - workout + - deep \ No newline at end of file diff --git a/php/php-core/variables-and-data-types-php/assignment-operators-php.md b/php/php-core/variables-php/assignment-operators-php.md similarity index 68% rename from php/php-core/variables-and-data-types-php/assignment-operators-php.md rename to php/php-core/variables-php/assignment-operators-php.md index cd215b4cb6..7494b2a8cb 100644 --- a/php/php-core/variables-and-data-types-php/assignment-operators-php.md +++ b/php/php-core/variables-php/assignment-operators-php.md @@ -21,18 +21,7 @@ revisionQuestion: In **PHP**, assignment operators are used to assign values to variables. -The most common assignment operator is the `=` operator, which is used to assign a value to a variable: -```php -$x = 7; -$y = 13; - -echo $x; -// Outputs: 7 -echo $y; -// Outputs: 13 -``` - -**PHP** also includes compound assignment operators such as `+=`, `-=`, `*=`, and `/=`. These operators modify the value of the variable: +Other than `=`, **PHP** also includes compound assignment operators such as `+=`, `-=`, `*=`, and `/=`. ```php // equivalent to $x = $x + 5 @@ -63,7 +52,7 @@ Which operator is used to assign a value to a variable in **PHP**? Which of these variables uses the recommended way of assigning values in **PHP**? -```plain-text +```php x = 2; $y = 10; ``` diff --git a/php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md b/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md similarity index 64% rename from php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md rename to php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md index 956b8a76fb..50e6327ba6 100644 --- a/php/php-core/variables-and-data-types-php/creating-and-storing-variables-in-php.md +++ b/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md @@ -14,30 +14,15 @@ revisionQuestion: --- -# Creating and Storing Variables +# Creating and Storing Variables(ii) --- ## Content -Variables are crucial in programming. They are named locations in memory that store a value, which can be later retrieved and used. They allow us to store and manipulate data in a program. - -In **PHP**, variables are declared with a dollar sign `$` and do not require a type to be specified: -```csharp -$x = 5; -$y = 10.0; -``` - -To print the value of a variable we use `echo`: -```csharp -echo $x; -// Outputs: 5 -echo $y; -// Outputs: 10.0 -``` You can also create variables using other variables: -```csharp +```php $z = $x + $y; echo $z; // Outputs: 15.0 diff --git a/php/php-core/variables-php/creating-and-storing-variables-in-php.md b/php/php-core/variables-php/creating-and-storing-variables-in-php.md new file mode 100644 index 0000000000..9d560c58d7 --- /dev/null +++ b/php/php-core/variables-php/creating-and-storing-variables-in-php.md @@ -0,0 +1,27 @@ +--- +author: Stefan-Stojanovic +type: normal +category: must-know +--- + +# Creating and Storing Variables + +--- + +## Content + +Variables are crucial in programming. They are named locations in memory that store a value, which can be later retrieved and used. They allow us to store and manipulate data in a program. + +In **PHP**, variables are declared with a dollar sign `$` and do not require a type to be specified: +```php +$x = 5; +$y = 10.0; +``` + +To print the value of a variable we use `echo`: +```php +echo $x; +// Outputs: 5 +echo $y; +// Outputs: 10.0 +``` diff --git a/php/php-core/variables-and-data-types-php/printing-variables-in-php.md b/php/php-core/variables-php/printing-variables-in-php.md similarity index 87% rename from php/php-core/variables-and-data-types-php/printing-variables-in-php.md rename to php/php-core/variables-php/printing-variables-in-php.md index 7cae3ea0fd..0b72a66ff7 100644 --- a/php/php-core/variables-and-data-types-php/printing-variables-in-php.md +++ b/php/php-core/variables-php/printing-variables-in-php.md @@ -10,7 +10,6 @@ revisionQuestion: formats: - fill-in-the-gap context: standalone - --- # Printing @@ -19,15 +18,9 @@ revisionQuestion: ## Content -In PHP, you can use the `echo` language construct to output messages: -```php -echo "Hello, world!"; -``` - If you want to print[1] a message and move to a new line, you can use the newline character `\n`. **Note** that the newline character only works in double-quoted strings: - ```php echo "Hello, world!\n"; ``` @@ -36,8 +29,6 @@ To print the type of variable, we can use `var_dumb`: ```php $name = "Stefan"; var_dump($name); - -// type of variable and its value // string(6) "Stefan" ``` From e34c2d9c1e48103530f84890c9a542dedc552319 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Thu, 19 Oct 2023 11:33:26 -0400 Subject: [PATCH 08/22] Readme fix --- php/php-core/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/php-core/README.md b/php/php-core/README.md index 22a5888a9f..eec73ccbae 100644 --- a/php/php-core/README.md +++ b/php/php-core/README.md @@ -7,7 +7,8 @@ core: true sections: '0': - intro-to-php - - variables-and-data-types-php + - variables-php + - data-types-php - control-flow-i-php - logical-operators-php - looping-php From bbf622018a1234e09b2f0a9eb5b19491fd83b7b5 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 14:50:13 -0400 Subject: [PATCH 09/22] logops fi --- .../and-precedence-php.md | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/php/php-core/logical-operators-php/and-precedence-php.md b/php/php-core/logical-operators-php/and-precedence-php.md index 6defc09942..bb2d380217 100644 --- a/php/php-core/logical-operators-php/and-precedence-php.md +++ b/php/php-core/logical-operators-php/and-precedence-php.md @@ -24,43 +24,31 @@ links: ## Content -The `and` and `&&` operators differ in their precedence. The `&&` operator has a higher precedence. -Note: This only applies if both are used at the same time. The presedence doesn't matter when only one of them is used. +In PHP, `&&` takes precedence over `and`. When mixed, this order matters. Let's look at an example: -```cpp +```php $a = true; $b = false; $c = true; if($a and $b && $c) { - echo "This will not print."; + // Interpreted as: ($a and $b) && $c + echo "Won't print."; } else { - echo "This will print."; + echo "Will print."; } -// Output: "This will print." if($a && $b and $c) { - echo "This will not print."; + // Interpreted as: $a && ($b and $c) + echo "Won't print."; } else { - echo "This will print."; + echo "Will print."; } -// Output: "This will not print." ``` - -In the first `if` statement, `$a` and `$b` && `$c` is evaluated like `($a and $b) && $c` due to `&&` having higher precedence. - -So it first evaluates `$a` and `$b` which results in false (since `$b` is false), and then false && `$c` is also false. - -In the second `if` statement, `$a` && `$b` and `$c` is evaluated like `$a && ($b and $c)`. - -So it first evaluates `$b` and `$c` which results in false (since `$b` is false), and then `$a` && false is also false. - -So be careful when mixing `and` and `&&` in the same expression because `&&` has a higher precedence and will be evaluated first. - -To avoid confusion, stick with one type of operator, or use parentheses to make the precedence explicit. +For clarity, use one operator type or add parentheses. --- From 4a8a0ea152c3d59a1ffb5aa1a77cf6fafa6cb322 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 14:53:28 -0400 Subject: [PATCH 10/22] Control-flow fix --- .../control-flow-i-php/comparison-operators-php.md | 13 ------------- .../nested-if-else-statements-php.md | 14 ++------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/php/php-core/control-flow-i-php/comparison-operators-php.md b/php/php-core/control-flow-i-php/comparison-operators-php.md index b8c9506972..09e581c796 100644 --- a/php/php-core/control-flow-i-php/comparison-operators-php.md +++ b/php/php-core/control-flow-i-php/comparison-operators-php.md @@ -36,17 +36,6 @@ Here's a table of comparison operators you can use: | >= | is greater than or equal to | ```php -$num = 1; -if ($num == 1) { // true - echo "num is $num"; -} -// num is 1 - -if ($num >= 1) { // true - echo "$num is greater than or equal to 1"; -} -// 1 is greater than or equal to 1 - if ($num < 5) { // true echo "$num is less than 5"; } @@ -56,8 +45,6 @@ if ($num != 2) { // true echo "$num doesn't equal 2"; } // 1 doesn't equal 2 - -// ... ``` diff --git a/php/php-core/control-flow-i-php/nested-if-else-statements-php.md b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md index f0d2dae0da..831022d266 100644 --- a/php/php-core/control-flow-i-php/nested-if-else-statements-php.md +++ b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md @@ -40,19 +40,9 @@ if($age >= 18){ else{ echo "You are not an adult."; } -``` - -In this example, the program first checks if `age` is greater than or equal to 18. - -If true, it enters the next level of the `if` statement and checks if `age` is less than or equal to 60. - -If true, it outputs `"You are an adult."` - -If false, it outputs `"You are a senior."` - -If the first `if` condition is false, it outputs `"You are not an adult."`. - +// Output: "You are an adult." +``` --- From 43a2147b923df917a6b9dbc6240b4aaaa9ca1779 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:05:17 -0400 Subject: [PATCH 11/22] Some table fixes --- .../control-flow-i-php/comparison-operators-php.md | 5 +---- php/php-core/control-flow-i-php/if-statements-php.md | 6 +----- .../what-are-logical-operators-php.md | 12 ++++++------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/php/php-core/control-flow-i-php/comparison-operators-php.md b/php/php-core/control-flow-i-php/comparison-operators-php.md index 09e581c796..7a44958fb1 100644 --- a/php/php-core/control-flow-i-php/comparison-operators-php.md +++ b/php/php-core/control-flow-i-php/comparison-operators-php.md @@ -20,11 +20,8 @@ revisionQuestion: ## Content -Comparison operators can be used to compare various types of data, including numbers, strings, and booleans. +Comparison operators can be used to compare various types of data, including numbers, strings, and booleans: -PHP's comparison operators are flexible and can handle different data types appropriately. - -Here's a table of comparison operators you can use: | Operator | Name | |:--------:|:---------------------------:| diff --git a/php/php-core/control-flow-i-php/if-statements-php.md b/php/php-core/control-flow-i-php/if-statements-php.md index ef69811b9a..9901245c37 100644 --- a/php/php-core/control-flow-i-php/if-statements-php.md +++ b/php/php-core/control-flow-i-php/if-statements-php.md @@ -35,11 +35,7 @@ $num = 5; if ($num > 0) { echo "$num is a positive number"; } -``` - -The above would output: -```plain-text -5 is a positive number +// Output: 5 is a positive number ``` If the condition `$num > 0` evaluates to `false`, this code would not output anything. diff --git a/php/php-core/logical-operators-php/what-are-logical-operators-php.md b/php/php-core/logical-operators-php/what-are-logical-operators-php.md index 366d952e9a..74be06860f 100644 --- a/php/php-core/logical-operators-php/what-are-logical-operators-php.md +++ b/php/php-core/logical-operators-php/what-are-logical-operators-php.md @@ -21,10 +21,10 @@ The logical operators provided by PHP include: | Operator | Name | |:--------:|:----:| -| and | AND | -| or | OR | -| xor | XOR | -| ! | NOT | -| && | AND | -| || | OR | +| `and` | AND | +| `or` | OR | +| `xor` | XOR | +| `!` | NOT | +| `&&` | AND | +| `⎮⎮` | OR | From 164856ea156c78f97ec8133b08c9454184337be5 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:10:23 -0400 Subject: [PATCH 12/22] Code snippet fixes --- php/php-core/logical-operators-php/and-php.md | 22 +++++-------------- .../and-precedence-php.md | 4 ++-- php/php-core/logical-operators-php/not-php.md | 6 ++--- php/php-core/logical-operators-php/or-php.md | 14 ++---------- php/php-core/logical-operators-php/xor-php.md | 4 ++-- .../more-data-types-php/arrays-php.md | 4 ++-- ...reating-and-storing-variables-in-php-ii.md | 2 +- 7 files changed, 18 insertions(+), 38 deletions(-) diff --git a/php/php-core/logical-operators-php/and-php.md b/php/php-core/logical-operators-php/and-php.md index 529d293636..f0f40dcb20 100644 --- a/php/php-core/logical-operators-php/and-php.md +++ b/php/php-core/logical-operators-php/and-php.md @@ -24,28 +24,18 @@ The `and` and `&&` operators in **PHP** return true only if both operands are tr Here are some examples: -```cpp +```php $a = true; -$b = false; +$b = true; if($a && $b) { echo "Both a and b are true."; -} else { - echo "Either a, b or both are false."; } -// Output: "Either a or b is false." -``` - -```cpp -$a = true; -$b = false; - +// Output: "Both a and b are true." if($a and $b) { echo "Both a and b are true."; -} else { - echo "Either a, b or both are false."; } -// Output: "Either a or b is false." +// Output: "Both a and b are true." ``` Note that there is a difference in precedence between `and` and `&&`. We will look at an example in the next insight. @@ -56,7 +46,7 @@ Note that there is a difference in precedence between `and` and `&&`. We will lo Complete the following code so that the output is "Both a and b are true.": -```cpp +```php $a = ???; $b = true; @@ -78,7 +68,7 @@ if($a ??? $b) { What is the output of the following code? -```cpp +```php $a = false; $b = true; diff --git a/php/php-core/logical-operators-php/and-precedence-php.md b/php/php-core/logical-operators-php/and-precedence-php.md index bb2d380217..fd6deb12f1 100644 --- a/php/php-core/logical-operators-php/and-precedence-php.md +++ b/php/php-core/logical-operators-php/and-precedence-php.md @@ -56,7 +56,7 @@ For clarity, use one operator type or add parentheses. Complete the following code so that the output is "Both a and b are true.": -```cpp +```php $a = ???; $b = true; @@ -78,7 +78,7 @@ if($a ??? $b) { What is the output of the following code? -```cpp +```php $a = false; $b = true; diff --git a/php/php-core/logical-operators-php/not-php.md b/php/php-core/logical-operators-php/not-php.md index b11fe04aae..a4bd3248ca 100644 --- a/php/php-core/logical-operators-php/not-php.md +++ b/php/php-core/logical-operators-php/not-php.md @@ -22,7 +22,7 @@ revisionQuestion: The `!` operator returns the inverse of the operand's boolean value. If the operand is true, it returns false, and vice versa. -```cpp +```php bool a = true; if(!a) { @@ -39,7 +39,7 @@ if(!a) { Finish the code to output 'a is false'? -```cpp +```php $a = ???; if(???) { @@ -61,7 +61,7 @@ if(???) { What is the output of the following code? -```cpp +```php $a = true; if(!$a) { diff --git a/php/php-core/logical-operators-php/or-php.md b/php/php-core/logical-operators-php/or-php.md index fdc78b30c8..c49154c6de 100644 --- a/php/php-core/logical-operators-php/or-php.md +++ b/php/php-core/logical-operators-php/or-php.md @@ -29,20 +29,10 @@ $b = false; if($a || $b) { echo "At least one of a or b is true."; -} else { - echo "Both a and b are false."; } // Output: "At least one of a or b is true." -``` - -```php -$a = true; -$b = false; - if($a or $b) { echo "At least one of a or b is true."; -} else { - echo "Both a and b are false."; } // Output: "At least one of a or b is true." ``` @@ -55,7 +45,7 @@ Just like the `and` and `&&` operators, `or` and `||` have different precedence. What is the output of the following code? -```cpp +```php $a = false; $b = false; @@ -77,7 +67,7 @@ if($a || $b) { What is the output of the following code? -```cpp +```php $a = true; $b = false; diff --git a/php/php-core/logical-operators-php/xor-php.md b/php/php-core/logical-operators-php/xor-php.md index 6cabb292cd..9d32151385 100644 --- a/php/php-core/logical-operators-php/xor-php.md +++ b/php/php-core/logical-operators-php/xor-php.md @@ -41,7 +41,7 @@ if($a xor $b) { What is the output of the following code? -```cpp +```php $a = true; $b = true; @@ -62,7 +62,7 @@ if($a xor $b) { What is the output of the following code? -```cpp +```php $a = false; $b = false; diff --git a/php/php-core/more-data-types-php/arrays-php.md b/php/php-core/more-data-types-php/arrays-php.md index 57eef7e868..17feec852e 100644 --- a/php/php-core/more-data-types-php/arrays-php.md +++ b/php/php-core/more-data-types-php/arrays-php.md @@ -70,7 +70,7 @@ Array Fill in the code to create an array of integers called `nums` that hold numbers from 1 through 5: -```csharp +```php ??? = ???(1, 2, 3, 4, 5); ``` @@ -85,7 +85,7 @@ Fill in the code to create an array of integers called `nums` that hold numbers ## Revision Fill in the code to output the number 7 from the `numbers` array using its index: -```csharp +```php $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); echo $numbers[???]; // Output: 7 diff --git a/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md b/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md index 50e6327ba6..55465df116 100644 --- a/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md +++ b/php/php-core/variables-php/creating-and-storing-variables-in-php-ii.md @@ -52,7 +52,7 @@ Which of the following is the correct way to create a variable in **PHP**? ## Revision Finish the code to create a new variable called `c` by summing the values of the `a` and `b` variables. Print the new variable. -```cpp +```php $a = 3; $b = 7; From d16089b3f2ce0dab21c5253c54f23eb5be34f954 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:21:12 -0400 Subject: [PATCH 13/22] Arrays setup --- .../data-types-php/basic-data-types-php.md | 1 - php/php-core/more-data-types-php/README.md | 2 + .../array-functions-php.md | 13 +----- .../arrays-as-dicts-php.md | 44 +++++++++++++++++++ .../arrays-functions-php-ii.md | 32 ++++++++++++++ .../more-data-types-php/arrays-php.md | 30 ------------- 6 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 php/php-core/more-data-types-php/arrays-as-dicts-php.md create mode 100644 php/php-core/more-data-types-php/arrays-functions-php-ii.md diff --git a/php/php-core/data-types-php/basic-data-types-php.md b/php/php-core/data-types-php/basic-data-types-php.md index 82aa085d21..5b42fcd00d 100644 --- a/php/php-core/data-types-php/basic-data-types-php.md +++ b/php/php-core/data-types-php/basic-data-types-php.md @@ -25,7 +25,6 @@ In PHP, variable are loosely typed, meaning that they are converted automaticall ### Compound types - - `array` for storing multiple values in a single variable. - `object` for storing instances of classes. diff --git a/php/php-core/more-data-types-php/README.md b/php/php-core/more-data-types-php/README.md index cf8c6cf6cf..38e2c9826f 100644 --- a/php/php-core/more-data-types-php/README.md +++ b/php/php-core/more-data-types-php/README.md @@ -4,7 +4,9 @@ description: Compound and Special Data insights: - arrays-php + - arrays-as-dicts-php - array-functions-php + - array-functions-php-ii aspects: - introduction diff --git a/php/php-core/more-data-types-php/array-functions-php.md b/php/php-core/more-data-types-php/array-functions-php.md index 7718f6b9ce..308b704bd2 100644 --- a/php/php-core/more-data-types-php/array-functions-php.md +++ b/php/php-core/more-data-types-php/array-functions-php.md @@ -13,29 +13,18 @@ category: must-know ## Content -**PHP** provides a large number of built-in functions for manipulating arrays: +Some of the most important array functions in *PHP* are: - `count()`: returns the number of elements in an array. -- `sort()`: sorts the elements of an array in ascending order. -- `rsort()`: sorts the elements of an array in descending order. - `array_push()`: pushes one or more elements onto the end of an array. - `array_pop()`: pops and returns the last value of the array, shortening the array by one element. - ```php $numbers = array(2, 3, 1); echo "Count: " . count($numbers) . "\n"; // Output: Count: 3 -sort($numbers); -echo "Sorted: " . implode(", ", $numbers) . "\n"; -// Output: Sorted: 1, 2, 3 - -rsort($numbers); -echo "Reversed: " . implode(", ", $numbers) . "\n"; -// Output: Reversed: 3, 2, 1 - // Add more elements array_push($numbers, 4, 5, 6); diff --git a/php/php-core/more-data-types-php/arrays-as-dicts-php.md b/php/php-core/more-data-types-php/arrays-as-dicts-php.md new file mode 100644 index 0000000000..3869c0a72e --- /dev/null +++ b/php/php-core/more-data-types-php/arrays-as-dicts-php.md @@ -0,0 +1,44 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know +--- + +# Arrays as Dictionaries + +--- + +## Content + + +Arrays in PHP can also be used as dicitonaries, where you can assign keys to the values: +```php +$numbers = array( + 'one' => 1, + 'two' => 2, + 'three' => 3, + 'four' => 4, + 'five' => 5 +); +``` + +For outputting the contents of the whole array, we can use the `print_r()` function: +```php +print_r($numbers); +``` + +Which gives us this output: +```php +Array +( + [one] => 1 + [two] => 2 + [three] => 3 + [four] => 4 + [five] => 5 +) +``` + + diff --git a/php/php-core/more-data-types-php/arrays-functions-php-ii.md b/php/php-core/more-data-types-php/arrays-functions-php-ii.md new file mode 100644 index 0000000000..4651e95a3e --- /dev/null +++ b/php/php-core/more-data-types-php/arrays-functions-php-ii.md @@ -0,0 +1,32 @@ +--- +author: Stefan-Stojanovic +tags: + - introduction +type: normal +category: must-know + +--- + +# Array Sorting + +--- + +## Content + +**PHP** also includes built-in functions for sorting arrays: + +- `sort()`: sorts the elements of an array in ascending order. +- `rsort()`: sorts the elements of an array in descending order. + +```php +$numbers = array(2, 3, 1); + +sort($numbers); +echo "Sorted: " . implode(", ", $numbers) . "\n"; +// Output: Sorted: 1, 2, 3 + +rsort($numbers); +echo "Reversed: " . implode(", ", $numbers) . "\n"; +// Output: Reversed: 3, 2, 1 +``` + diff --git a/php/php-core/more-data-types-php/arrays-php.md b/php/php-core/more-data-types-php/arrays-php.md index 17feec852e..e8b0ebc54e 100644 --- a/php/php-core/more-data-types-php/arrays-php.md +++ b/php/php-core/more-data-types-php/arrays-php.md @@ -34,36 +34,6 @@ echo $numbers[0]; // Output: 1 ``` -Arrays in PHP can also be associative, where you can assign keys to the values: -```php -$numbers = array( - 'one' => 1, - 'two' => 2, - 'three' => 3, - 'four' => 4, - 'five' => 5 -); -``` - -For outputting the contents of the whole array, we can use the `print_r()` function: -```php -print_r($numbers); -``` - -Which gives us this output: -```php -Array -( - [one] => 1 - [two] => 2 - [three] => 3 - [four] => 4 - [five] => 5 -) -``` - - - --- ## Practice From 73bdd37e1aaacb24dc426787da67d8b513def053 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:22:40 -0400 Subject: [PATCH 14/22] Readme fix --- php/php-core/more-data-types-php/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/php-core/more-data-types-php/README.md b/php/php-core/more-data-types-php/README.md index 38e2c9826f..ecce04d1eb 100644 --- a/php/php-core/more-data-types-php/README.md +++ b/php/php-core/more-data-types-php/README.md @@ -6,7 +6,7 @@ insights: - arrays-php - arrays-as-dicts-php - array-functions-php - - array-functions-php-ii + - arrays-functions-php-ii aspects: - introduction From a06015cd9f78a5c2b14741e7857da23260749919 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:25:18 -0400 Subject: [PATCH 15/22] Changed italic to bold --- php/php-core/more-data-types-php/array-functions-php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/php-core/more-data-types-php/array-functions-php.md b/php/php-core/more-data-types-php/array-functions-php.md index 308b704bd2..e939631fea 100644 --- a/php/php-core/more-data-types-php/array-functions-php.md +++ b/php/php-core/more-data-types-php/array-functions-php.md @@ -13,7 +13,7 @@ category: must-know ## Content -Some of the most important array functions in *PHP* are: +Some of the most important array functions in **PHP** are: - `count()`: returns the number of elements in an array. - `array_push()`: pushes one or more elements onto the end of an array. From 4047aa06ea7cc0fb8782eda66d90d589687cade9 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:28:06 -0400 Subject: [PATCH 16/22] Intro change --- php/README.md | 2 +- php/php-core/intro-to-php/what-is-php.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/php/README.md b/php/README.md index 60d8442492..c6b21bdeeb 100644 --- a/php/README.md +++ b/php/README.md @@ -1,6 +1,6 @@ name: PHP -description: An efficient, powerful, low-level language +description: A powerful language for web development color: A6D8FF diff --git a/php/php-core/intro-to-php/what-is-php.md b/php/php-core/intro-to-php/what-is-php.md index 891df98f62..d4ca2bd3ec 100644 --- a/php/php-core/intro-to-php/what-is-php.md +++ b/php/php-core/intro-to-php/what-is-php.md @@ -3,7 +3,7 @@ author: Stefan-Stojanovic type: normal -category: must-know +category: discussion --- @@ -13,7 +13,9 @@ category: must-know ## Content -**PHP** is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. **PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser. +**PHP** is a widely-used open source general-purpose scripting language that is especially suited for web development. + +**PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser. A unique feature of **PHP** is that it can be embedded directly within HTML, which simplifies the creation of dynamic web pages. From c923c4f984b6104446df8eceecb14dd6d0d850e3 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Sun, 22 Oct 2023 15:42:31 -0400 Subject: [PATCH 17/22] Added logo --- php/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/README.md b/php/README.md index c6b21bdeeb..b42284c2fd 100644 --- a/php/README.md +++ b/php/README.md @@ -4,7 +4,7 @@ description: A powerful language for web development color: A6D8FF -icon: https://img.enkipro.com/6fc730e946778fd1474fb41ea0a91a7a.png +icon: https://img.enkipro.com/dbd5d4ad70bf69766e037505b5e8199f.png availableAspects: - introduction \ No newline at end of file From 943c0da424bc90339b75cf3bceb338f0350fe3f6 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Tue, 24 Oct 2023 09:20:44 -0400 Subject: [PATCH 18/22] Redoing intro php --- php/php-core/intro-to-php/README.md | 1 - .../intro-to-php/first-program-php.md | 29 ++++++++++++++++++- php/php-core/intro-to-php/what-is-php.md | 21 +++++++++++--- php/php-core/intro-to-php/why-learn-php.md | 20 +++++++++++-- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/php/php-core/intro-to-php/README.md b/php/php-core/intro-to-php/README.md index 69ab07173a..44b051658c 100644 --- a/php/php-core/intro-to-php/README.md +++ b/php/php-core/intro-to-php/README.md @@ -5,7 +5,6 @@ description: What is PHP? insights: - what-is-php - why-learn-php - - installing-php-locally - first-program-php aspects: diff --git a/php/php-core/intro-to-php/first-program-php.md b/php/php-core/intro-to-php/first-program-php.md index d9f53ea703..c0f03aeec1 100644 --- a/php/php-core/intro-to-php/first-program-php.md +++ b/php/php-core/intro-to-php/first-program-php.md @@ -36,13 +36,40 @@ echo "Hello, World!"; // Hello, World! ``` -To run the program, you can save it to a script file with the `.cpp` extension, for instance `hello.cpp` and run it using this command: +Once you have PHP installed[1], you can save your program to a script file with the `.php` extension, for instance `hello.php` and run it using this command: ```php php hello.php ``` You should see the text "Hello, World!" printed to the screen. +--- +## Footnotes + +[1: Installing PHP] +To install **PHP**, you can follow these steps: + +### Windows + +Download the VC15 x64 Non Thread Safe version from the official [PHP website](https://windows.php.net/download/). Then, extract the zip file to a directory. + +### Linux + +**PHP** can be installed via the package manager. For example, on Ubuntu, you would use this command: +```bash +sudo apt install php. +``` + +### MacOs + +On macOS, **PHP** is preinstalled, but you can use Homebrew to install a more recent version. + +```bash +brew install php +``` + +Once the installation is complete, you can start using **PHP** by writing scripts and running them with the **PHP** command-line interface or with a web server that supports **PHP** (like Apache or Nginx). + --- ## Practice diff --git a/php/php-core/intro-to-php/what-is-php.md b/php/php-core/intro-to-php/what-is-php.md index d4ca2bd3ec..99b3670148 100644 --- a/php/php-core/intro-to-php/what-is-php.md +++ b/php/php-core/intro-to-php/what-is-php.md @@ -13,13 +13,12 @@ category: discussion ## Content -**PHP** is a widely-used open source general-purpose scripting language that is especially suited for web development. +**PHP** is a general-purpose scripting language used by over 75% of websites.[1] -**PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser. +**PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser.[2] -A unique feature of **PHP** is that it can be embedded directly within HTML, which simplifies the creation of dynamic web pages. +A unique feature of **PHP** is that it can be embedded directly within HTML: -Here's an example of **PHP** embedded in HTML: ```php @@ -42,3 +41,17 @@ echo "Hello, world!"; > > Leave a comment or view some of the other comments for inspiration before moving on. +--- + +## Footnotes + +[1: PHP Usage] + +PHP is estimated to be used by [76.8% of all websites](https://w3techs.com/technologies/details/pl-php) + +[2: Server vs Client] + +The server is the computer which hosts and manages your web app. +The client is the user's device that is looking to use the web app. + +When a user wants to use your web app, their browser makes a requests to the server, the server will then execute the PHP code and return to the client the resulting website \ No newline at end of file diff --git a/php/php-core/intro-to-php/why-learn-php.md b/php/php-core/intro-to-php/why-learn-php.md index f88e1ee259..e9d49cd5fd 100644 --- a/php/php-core/intro-to-php/why-learn-php.md +++ b/php/php-core/intro-to-php/why-learn-php.md @@ -15,9 +15,23 @@ category: must-know There are several reasons why learning **PHP** can be beneficial: -- **PHP** has a straightforward learning curve, making it an excellent choice for beginners looking to step into back-end web development. +- **PHP** is the primary language used in WordPress development, which powers over **40% of all websites**[1] - It is fully embedded within **HTML**, making it a great language for creating dynamic web pages. - **PHP** has extensive online documentation and a large community, making it easier to find help and resources. -- It is widely used, and skills in **PHP** are often sought after for web development roles. +- The average annual salary for a **PHP** developer is $90,000 dollars.[2] + +--- + +## Footnotes + +[1: Wordpress Usage] + +Wordpress is a content-management system(CMS) for people to build and publish websites. + +It is estimated to be used by [43% of all websites](https://w3techs.com/technologies/details/cm-wordpress) + +[2: PHP salary] + +Per Zippia, the estimated average PHP Developer Salary is [$91,010 as of October 2023](https://www.zippia.com/php-developer-jobs/salary/) + -Overall, learning **PHP** can open up opportunities in web development and help you build dynamic and interactive web applications. \ No newline at end of file From b90b0c22461858132b2259c4e77339156e1da15a Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Tue, 24 Oct 2023 09:33:03 -0400 Subject: [PATCH 19/22] Make it fun --- php/php-core/intro-to-php/what-is-php.md | 4 ++-- php/php-core/intro-to-php/why-learn-php.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/php/php-core/intro-to-php/what-is-php.md b/php/php-core/intro-to-php/what-is-php.md index 99b3670148..417dd16a60 100644 --- a/php/php-core/intro-to-php/what-is-php.md +++ b/php/php-core/intro-to-php/what-is-php.md @@ -13,7 +13,7 @@ category: discussion ## Content -**PHP** is a general-purpose scripting language used by over 75% of websites.[1] +**PHP** is a general-purpose scripting language used by over 75% of websites! [1] **PHP** code is executed on the server, and the plain HTML result is sent back to the client's browser.[2] @@ -34,7 +34,7 @@ echo "Hello, world!"; ``` -> Do not worry if you do not understand the code, this is just an example to get you confortable with the syntax. We will dive deeper into it later on. +> Don't worry if you do not understand the code, this is just an example to get you confortable with the syntax. We will dive deeper into it later on. > 💬 Why are you interested in **PHP**? diff --git a/php/php-core/intro-to-php/why-learn-php.md b/php/php-core/intro-to-php/why-learn-php.md index e9d49cd5fd..c9aaca72fd 100644 --- a/php/php-core/intro-to-php/why-learn-php.md +++ b/php/php-core/intro-to-php/why-learn-php.md @@ -15,10 +15,10 @@ category: must-know There are several reasons why learning **PHP** can be beneficial: -- **PHP** is the primary language used in WordPress development, which powers over **40% of all websites**[1] -- It is fully embedded within **HTML**, making it a great language for creating dynamic web pages. +- **PHP** is the primary language used in WordPress development, which powers over **40% of all websites**![1] +- 🌐 It is fully embedded within **HTML**, making it a great language for creating dynamic web pages. - **PHP** has extensive online documentation and a large community, making it easier to find help and resources. -- The average annual salary for a **PHP** developer is $90,000 dollars.[2] +- 💰💰💰 The average annual salary for a **PHP** developer is $90,000 dollars.[2] --- From 22509519f01dd702fde46d63a0978a02cd49b9b6 Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Tue, 24 Oct 2023 09:34:40 -0400 Subject: [PATCH 20/22] footnote fix --- php/php-core/intro-to-php/why-learn-php.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/php-core/intro-to-php/why-learn-php.md b/php/php-core/intro-to-php/why-learn-php.md index c9aaca72fd..3b952703c5 100644 --- a/php/php-core/intro-to-php/why-learn-php.md +++ b/php/php-core/intro-to-php/why-learn-php.md @@ -15,7 +15,7 @@ category: must-know There are several reasons why learning **PHP** can be beneficial: -- **PHP** is the primary language used in WordPress development, which powers over **40% of all websites**![1] +- **PHP** is the primary language used in WordPress development, which powers over **40% of all websites**! [1] - 🌐 It is fully embedded within **HTML**, making it a great language for creating dynamic web pages. - **PHP** has extensive online documentation and a large community, making it easier to find help and resources. - 💰💰💰 The average annual salary for a **PHP** developer is $90,000 dollars.[2] From 78796082415783fe5fead4fc91de7304dbfc8c2f Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Wed, 1 Nov 2023 13:54:56 -0400 Subject: [PATCH 21/22] Change logo and minor changes --- php/README.md | 2 +- .../nested-if-else-statements-php.md | 1 - .../intro-to-php/first-program-php.md | 6 +-- .../intro-to-php/installing-php-locally.md | 36 ------------- php/php-core/intro-to-php/what-is-php.md | 2 +- php/php-core/logical-operators-php/and-php.md | 51 +------------------ php/php-core/logical-operators-php/or-php.md | 49 ------------------ php/php-core/variables-php/README.md | 1 + 8 files changed, 7 insertions(+), 141 deletions(-) delete mode 100644 php/php-core/intro-to-php/installing-php-locally.md diff --git a/php/README.md b/php/README.md index b42284c2fd..32ed995fd8 100644 --- a/php/README.md +++ b/php/README.md @@ -4,7 +4,7 @@ description: A powerful language for web development color: A6D8FF -icon: https://img.enkipro.com/dbd5d4ad70bf69766e037505b5e8199f.png +icon: https://img.enkipro.com/3b93389af57a5f6359e50d207274df29.png availableAspects: - introduction \ No newline at end of file diff --git a/php/php-core/control-flow-i-php/nested-if-else-statements-php.md b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md index 831022d266..389bdb2bde 100644 --- a/php/php-core/control-flow-i-php/nested-if-else-statements-php.md +++ b/php/php-core/control-flow-i-php/nested-if-else-statements-php.md @@ -7,7 +7,6 @@ category: must-know practiceQuestion: formats: - fill-in-the-gap - - type-in-the-gap context: standalone revisionQuestion: formats: diff --git a/php/php-core/intro-to-php/first-program-php.md b/php/php-core/intro-to-php/first-program-php.md index c0f03aeec1..e9d7f1d6d3 100644 --- a/php/php-core/intro-to-php/first-program-php.md +++ b/php/php-core/intro-to-php/first-program-php.md @@ -23,12 +23,12 @@ revisionQuestion: Ready for some code? -It's time to create our first program! Let's create a `"Hello, World!"` one. +It's time to create our first program! `"Hello, World!"` is a simple program that prints the text `"Hello, World!"` to the screen. It is often used as a starting point when learning a new programming language. In **PHP**, you can print text to the screen using the `echo` method. Here is an example: -```php +```html @@ -37,7 +37,7 @@ echo "Hello, World!"; ``` Once you have PHP installed[1], you can save your program to a script file with the `.php` extension, for instance `hello.php` and run it using this command: -```php +```bash php hello.php ``` diff --git a/php/php-core/intro-to-php/installing-php-locally.md b/php/php-core/intro-to-php/installing-php-locally.md deleted file mode 100644 index 0eb0a01e25..0000000000 --- a/php/php-core/intro-to-php/installing-php-locally.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -author: Stefan-Stojanovic -type: normal -category: tip - ---- - -# Installing PHP Locally - - ---- - -## Content - -To install **PHP**, you can follow these steps: - -### Windows - -Download the VC15 x64 Non Thread Safe version from the official [PHP website](https://windows.php.net/download/). Then, extract the zip file to a directory. - -### Linux - -**PHP** can be installed via the package manager. For example, on Ubuntu, you would use this command: -```bash -sudo apt install php. -``` - -### MacOs - -On macOS, **PHP** is preinstalled, but you can use Homebrew to install a more recent version. - -```bash -brew install php -``` - -Once the installation is complete, you can start using **PHP** by writing scripts and running them with the **PHP** command-line interface or with a web server that supports **PHP** (like Apache or Nginx). \ No newline at end of file diff --git a/php/php-core/intro-to-php/what-is-php.md b/php/php-core/intro-to-php/what-is-php.md index 417dd16a60..207f0a751a 100644 --- a/php/php-core/intro-to-php/what-is-php.md +++ b/php/php-core/intro-to-php/what-is-php.md @@ -19,7 +19,7 @@ category: discussion A unique feature of **PHP** is that it can be embedded directly within HTML: -```php +```html diff --git a/php/php-core/logical-operators-php/and-php.md b/php/php-core/logical-operators-php/and-php.md index f0f40dcb20..5424891835 100644 --- a/php/php-core/logical-operators-php/and-php.md +++ b/php/php-core/logical-operators-php/and-php.md @@ -4,14 +4,6 @@ tags: - introduction type: normal category: must-know -practiceQuestion: - formats: - - fill-in-the-gap - context: standalone -revisionQuestion: - formats: - - fill-in-the-gap - context: standalone --- # AND (and, &&) Operators @@ -40,45 +32,4 @@ if($a and $b) { Note that there is a difference in precedence between `and` and `&&`. We will look at an example in the next insight. ---- - -## Practice - -Complete the following code so that the output is "Both a and b are true.": - -```php -$a = ???; -$b = true; - -if($a ??? $b) { - echo ???; -} else { - echo "Either a or b is false."; -} -// Output: "Both a and b are true." -``` - -- true -- && -- "Both a and b are true." - ---- - -## Revision - -What is the output of the following code? - -```php -$a = false; -$b = true; - -if($a && $b) { - echo "Both a and b are true."; -} else { - echo "Either a or b is false."; -} -// Output: ??? -``` - -- "Either a or b is false." -- "Both a and b are true." \ No newline at end of file +--- \ No newline at end of file diff --git a/php/php-core/logical-operators-php/or-php.md b/php/php-core/logical-operators-php/or-php.md index c49154c6de..3f6422848d 100644 --- a/php/php-core/logical-operators-php/or-php.md +++ b/php/php-core/logical-operators-php/or-php.md @@ -4,14 +4,6 @@ tags: - introduction type: normal category: must-know -practiceQuestion: - formats: - - fill-in-the-gap - context: standalone -revisionQuestion: - formats: - - fill-in-the-gap - context: standalone --- # OR (||, or) operator @@ -40,44 +32,3 @@ if($a or $b) { Just like the `and` and `&&` operators, `or` and `||` have different precedence. The `||` operator has a higher precedence than `or`. --- - -## Practice - -What is the output of the following code? - -```php -$a = false; -$b = false; - -if($a || $b) { - echo "At least one of a or b is true."; -} else { - echo "Both a and b are false."; -} -// Output: ??? - -``` - -- "Either a, b or both a and b are true." -- "Both a and b is false." - ---- - -## Revision - -What is the output of the following code? - -```php -$a = true; -$b = false; - -if($a || $b) { - echo "At least one of a or b is true."; -} else { - echo "Both a and b are false."; -} -// Output: ??? -``` - -- "Both a and b is false." -- "Either a, b or both a and b are true." \ No newline at end of file diff --git a/php/php-core/variables-php/README.md b/php/php-core/variables-php/README.md index fd37fb6c57..754f7a1e72 100644 --- a/php/php-core/variables-php/README.md +++ b/php/php-core/variables-php/README.md @@ -4,6 +4,7 @@ description: Learn about variables in PHP. insights: - creating-and-storing-variables-in-php + - creating-and-storing-variables-in-php-ii - assignment-operators-php - printing-variables-in-php From 9ded0962819b0cf6ad69cb4be76e9d8eddaea92d Mon Sep 17 00:00:00 2001 From: Lior Ben-David Date: Thu, 16 Nov 2023 12:34:51 -0500 Subject: [PATCH 22/22] Retrigger --- php/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/php/README.md b/php/README.md index 32ed995fd8..331d072dcf 100644 --- a/php/README.md +++ b/php/README.md @@ -5,6 +5,5 @@ description: A powerful language for web development color: A6D8FF icon: https://img.enkipro.com/3b93389af57a5f6359e50d207274df29.png - availableAspects: - introduction \ No newline at end of file