Professional Documents
Culture Documents
Variable names in PHP start with the dollar sign ($) followed by the variable name. Here are some key
points about variables in PHP:
- Variable names must start with a letter or underscore (_), followed by letters, numbers, or
underscores.
2. **Variable Assignment**:
Variables in PHP are assigned values using the assignment operator (=). For example:
```php
$name = "John";
$age = 25;
```
3. **Data Types**:
- PHP supports different variable scopes, including global, local, static, and superglobal.
- Variables declared outside of functions are considered global and can be accessed from anywhere in
the script.
- Variables declared within a function are local to that function and cannot be accessed outside of it
unless explicitly declared as global or passed as function arguments.
5. **Variable Output**:
Variables can be output directly within double-quoted strings using variable interpolation or
concatenated with strings using the dot (.) operator. For example:
```php
```
6. **Variable Manipulation**:
Variables in PHP can be manipulated using various operators, functions, and language constructs. For
example, arithmetic operations, string concatenation, and array manipulation.
```php
$name = "Alice";
$age = 30;
$isStudent = true;
```
This code declares variables for name, age, and student status and then outputs their values.