PHP
PHP
It can be
embedded in HTML to add dynamic content and interact with databases. Let's break down the basic
syntax and semantics:
```php
<?php
?>
```
### 2. **Variables**
```php
<?php
?>
```
### 4. **Echo/Print**
```php
<?php
?>
```
### 5. **Concatenation**
```php
<?php
echo $greeting;
?>
```
```php
<?php
echo "Adult";
} else {
}
?>
```
```php
<?php
$day = "Monday";
switch ($day) {
case "Monday":
break;
case "Tuesday":
break;
default:
?>
```
#### **Loops:**
- **For loop:**
```php
<?php
echo $i;
?>
```
- **While loop:**
```php
<?php
$i = 0;
echo $i;
$i++;
?>
```
### 7. **Functions**
```php
<?php
function sayHello() {
echo "Hello!";
sayHello();
?>
```
```php
<?php
return $a + $b;
}
echo add(3, 4); // Outputs 7
?>
```
### 8. **Superglobals**
```php
<input type="submit">
</form>
<?php
// submit.php
$name = $_POST['name'];
?>
```
### 9. **Arrays**
```php
<?php
?>
```
```php
<?php
?>
```
```php
<?php
class Car {
public $make;
public $model;
$this->make = $make;
$this->model = $model;
}
$myCar = new Car("Toyota", "Corolla");
?>
```
```php
<?php
try {
?>
```
```php
<?php
// Single-line comment
/*
Multi-line comment
*/
?>
```
### Semantics
- **Interpreted Language:** PHP is executed on the server, and the result is sent to the browser.
- **Scope:** Variables declared inside a function are local to that function, unless declared global.