Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP #3275

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: PHP

description: A powerful language for web development

color: A6D8FF

icon: https://img.enkipro.com/3b93389af57a5f6359e50d207274df29.png
availableAspects:
- introduction
15 changes: 15 additions & 0 deletions php/php-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: PHP Core

description: Basic Syntax and Functionality

core: true

sections:
'0':
- intro-to-php
- variables-php
- data-types-php
- control-flow-i-php
- logical-operators-php
- looping-php
- more-data-types-php
12 changes: 12 additions & 0 deletions php/php-core/control-flow-i-php/README.md
Original file line number Diff line number Diff line change
@@ -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-statements-php

aspects:
- introduction
83 changes: 83 additions & 0 deletions php/php-core/control-flow-i-php/comparison-operators-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
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:


| 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
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
72 changes: 72 additions & 0 deletions php/php-core/control-flow-i-php/if-else-statements-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
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
74 changes: 74 additions & 0 deletions php/php-core/control-flow-i-php/if-statements-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
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";
}
// Output: 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
98 changes: 98 additions & 0 deletions php/php-core/control-flow-i-php/nested-if-else-statements-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
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
---

# 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.";
}

// Output: "You are 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.
13 changes: 13 additions & 0 deletions php/php-core/data-types-php/README.md
Original file line number Diff line number Diff line change
@@ -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
Loading