Now that you've set up your PHP development environment, it's time to dive into the basics of PHP programming. In this lesson, we'll cover variables, data types, and operators, which are fundamental building blocks for writing PHP code.
In PHP, variables are used to store data that can be used and manipulated later in your code. Variables in PHP start with a dollar sign ($) followed by the variable name. Variable names are case-sensitive and must start with a letter or an underscore.
To assign a value to a variable, use the equal sign (=):
$name = "John Doe";
$age = 30;
$score = 85.5;
PHP supports several data types:
$string1 = 'Hello, World!';
$string2 = "Hello, World!";
$int1 = 42;
$int2 = -10;
$float1 = 3.14;
$float2 = -0.5;
$bool1 = true;
$bool2 = false;
$array1 = array(1, 2, 3, 4, 5);
$array2 = array("apple", "banana", "cherry");
class Person {
public $name;
public $age;
}
$person = new Person();
$person->name = "John Doe";
$person->age = 30;