1. **Hello World**:
```php
echo "Hello, World!";
```
This code simply prints "Hello, World!" to the screen. It's a basic example of how to output text in PHP.
2. **Variable Declaration**:
```php
$variable_name = "This is a variable.";
```
This code declares a variable named `$variable_name` and assigns it the string value "This is a variable." You can use variables to store and manipulate data in PHP.
3. **Conditional Statement (if-else)**:
```php
if ($condition) {
// Code to run if condition is true
} else {
// Code to run if condition is false
}
```
This code demonstrates a conditional statement. If the condition inside the parentheses evaluates to true, the code inside the first block will be executed; otherwise, the code inside the `else` block will run.
4. **Loop (for)**:
```php
for ($i = 0; $i < 5; $i++) {
// Code to repeat
}
```
This code creates a `for` loop that will execute the code inside the block five times. It's a common structure for repetitive tasks in PHP.
5. **Array Declaration**:
```php
$fruits = array("apple", "banana", "cherry");
```
This code defines an array called `$fruits` that contains three elements: "apple," "banana," and "cherry." Arrays are used to store collections of data in PHP.
```php
echo "Hello, World!";
```
This code simply prints "Hello, World!" to the screen. It's a basic example of how to output text in PHP.
2. **Variable Declaration**:
```php
$variable_name = "This is a variable.";
```
This code declares a variable named `$variable_name` and assigns it the string value "This is a variable." You can use variables to store and manipulate data in PHP.
3. **Conditional Statement (if-else)**:
```php
if ($condition) {
// Code to run if condition is true
} else {
// Code to run if condition is false
}
```
This code demonstrates a conditional statement. If the condition inside the parentheses evaluates to true, the code inside the first block will be executed; otherwise, the code inside the `else` block will run.
4. **Loop (for)**:
```php
for ($i = 0; $i < 5; $i++) {
// Code to repeat
}
```
This code creates a `for` loop that will execute the code inside the block five times. It's a common structure for repetitive tasks in PHP.
5. **Array Declaration**:
```php
$fruits = array("apple", "banana", "cherry");
```
This code defines an array called `$fruits` that contains three elements: "apple," "banana," and "cherry." Arrays are used to store collections of data in PHP.