🔹 1. Variables & Data Types
✅ Variables
Variables are used to store data.
👉 In PHP, variables start with $
$name = "Aditya";
$age = 25;
✅ Rules:
- Must start with
$ - Cannot start with a number
- Case-sensitive (
$name≠$Name)
✅ Data Types in PHP
| Type | Example | Description |
|---|---|---|
| String | "Hello" | Text |
| Integer | 10 | Whole numbers |
| Float | 10.5 | Decimal numbers |
| Boolean | true/false | True or false |
| Array | ["a", "b"] | Multiple values |
| Object | new ClassName() | Complex data |
$name = "Aditya"; // String
$age = 25; // Integer
$price = 99.99; // Float
$isActive = true; // Boolean
🔹 2. Constants
Constants are values that cannot be changed once defined.
define("SITE_NAME", "SOA Technology");
echo SITE_NAME;
✅ Rules:
- No
$symbol - Always global
- Value cannot be modified
🔹 3. Operators
Operators are used to perform operations on variables
➤ Arithmetic Operators
| Operator | Meaning |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
$a = 10;
$b = 5;
echo $a + $b; // 15
➤ Comparison Operators
| Operator | Meaning |
|---|---|
== | Equal |
=== | Equal (value + type) |
!= | Not equal |
> | Greater |
< | Less |
$a = 10;
$b = "10";var_dump($a == $b); // true
var_dump($a === $b); // false
➤ Logical Operators
| Operator | Meaning |
|---|---|
&& | AND |
| ` | |
! | NOT |
$x = true;
$y = false;var_dump($x && $y); // false
🔹 4. Echo vs Print
Both are used to display output
✅ echo
- Faster
- Can print multiple values
echo "Hello ", "World";
- Slower than echo
- Returns value (1)
print "Hello World";
🔥 Key Difference
| Feature | echo | |
|---|---|---|
| Speed | Faster | Slower |
| Multiple arguments | Yes | No |
| Return value | No | Yes (1) |
🔹 5. Comments
Comments are used to explain code (ignored by PHP)
➤ Single-line comment
// This is a comment
# This is also a comment
➤ Multi-line comment
/*
This is a
multi-line comment
*/
✅ Summary
- Variables store data (
$name) - Data types define the kind of data
- Constants are fixed values
- Operators perform operations
- echo & print show output
- Comments explain code






