Assign this or that in PHP

Find this useful? Support us: Star on GitHub 6
Category: Other | Language: PHP

To assign values to variables in PHP, you use the assignment operator =. The syntax for assigning a value to a variable is:

$variable_name = value;

Here's an example:

$name = "John";

This assigns the string value "John" to the variable $name.

You can assign different types of values to variables in PHP, including:

- Strings: "apple", "John", "Hello world"
- Numbers: 10, 3.14, -5
- Booleans: true or false

You can also assign the result of an expression or function call to a variable. Here are some examples:

$sum = 1 + 2; // assigns the value 3 to $sum
$length = strlen("Hello"); // assigns the value 5 to $length
$is_admin = ($username == "admin"); // assigns true or false to $is_admin, depending on the value of $username

Note that in PHP, variables must start with the $ symbol.