🚀 KRANE DIGITAL PROGRAMMING ACADEMY
Empowering the next generation of PHP developers
📖 Course Contents
Click any section to jump directly to that lesson
📚 SECTION 1: PHP Basics
📦 SECTION 2: Variables
🔧 SECTION 3: Operators
🤔 SECTION 4: Decision Making
🔄 SECTION 5: Loops
⚡ SECTION 6: Functions
📚 SECTION 7: Arrays
📝 SECTION 8: Strings
📂 SECTION 9: Includes & Requires
📝 SECTION 10: Forms
⏰ SECTION 11: Dates & Time
📁 SECTION 12: Files
🐛 SECTION 13: Error Handling
🍪 SECTION 14: Cookies & Sessions
💾 SECTION 15: Databases
🛡️ SECTION 16: Security
🔌 SECTION 17: APIs
PHP Mastery
Complete Course
Download Complete Course PDF
Get the entire course as a PDF book for offline study and reference.
📥 Download PDF Book📚 SECTION 1: PHP Basics
📌 LESSON 1.1: What is PHP?
PHP stands for PHP: Hypertext Preprocessor. It's a server-side scripting language designed specifically for web development.
Analogy: Imagine you're building a house:
- HTML is like the bricks and mortar - it creates the structure
- CSS is like the paint and wallpaper - it makes things look beautiful
- JavaScript is like the lights and switches - it adds interactivity
- PHP is like the ELECTRICAL WIRING behind the walls - you don't see it, but it makes everything work!
💡 Key Point: PHP runs on the SERVER, not in your browser. This means users never see your actual PHP code!
📌 LESSON 1.2: How PHP Works
When someone visits your PHP website:
- Browser requests a .php file from your server
- Server reads the PHP code and processes it
- Server executes any instructions (database queries, calculations, etc.)
- Server generates HTML based on the PHP code
- Server sends ONLY the HTML to the browser
- Browser displays the page - user never sees the PHP code!
📌 LESSON 1.3: Your First PHP Code
🌟 Hello World Example
Hello! I'm generated by PHP at: 2025-03-15 10:30:00
If you can see this, PHP is working perfectly!
<?php
// This is a PHP comment
echo 'Hello World!';
echo 'Generated at: ' . date('Y-m-d H:i:s');
?>📌 LESSON 1.4: PHP Syntax Rules
- PHP tags: <?php ... ?>
- Statements end with ; (semicolon)
- Variables start with $ (dollar sign)
- Comments: // for single line, /* */ for multi-line
- Echo outputs text to the browser
<?php // This is a single-line comment /* This is a multi-line comment */ echo 'Hello'; // This outputs text ?>
📦 SECTION 2: Variables - Storing Information
📌 LESSON 2.1: What are Variables?
Variables are like labeled boxes where you store information. In PHP, every variable starts with a $ sign.
Example: $name = "John"; stores the name John in a variable called $name
Result: John
<?php $student_name = 'John Doe'; $student_age = 25; $course_price = 299.99; ?>
📌 LESSON 2.2: Variable Naming Rules
- ✅ Start with $ followed by a letter or underscore
- ✅ Can contain letters, numbers, and underscores
- ❌ Cannot start with a number
- ❌ Cannot contain spaces or special characters except _
- ⚠️ Case-sensitive ($name and $Name are different)
- 💡 Be descriptive! $user_age is better than $ua
// Valid variable names $name = 'John'; $_age = 25; $user1 = 'Sarah'; $first_name = 'Jane'; // Invalid variable names // $1user = 'John'; // Can't start with number // $user-name = 'John'; // Hyphen not allowed // $user name = 'John'; // Space not allowed
📌 LESSON 2.3: Data Types
| Type | Example | Value | Description |
|---|---|---|---|
| String | $name = "John" | John | Text data |
| Integer | $age = 25 | 25 | Whole numbers |
| Float | $price = 99.99 | 99.99 | Decimal numbers |
| Boolean | $is_active = true | true | true/false |
| Array | $skills = [...] | PHP, MySQL, JavaScript | Collection of values |
| NULL | $data = null | null | No value |
<?php // Different data types $text = 'Hello'; // String $number = 42; // Integer $decimal = 3.14; // Float $is_true = true; // Boolean $fruits = ['apple', 'banana']; // Array $nothing = null; // NULL // Check the type echo gettype($text); // string echo gettype($number); // integer ?>
📌 LESSON 2.4: Type Juggling
PHP automatically converts types when needed:
"10" + 5 = 15 (string automatically converted to number)
"10 apples" + 5 = 15 (PHP takes the number at the beginning)
<?php // Automatic type conversion $total = '10' + 5; // 15 (string to integer) $combined = '5' . ' apples'; // '5 apples' (integer to string) $bool = 'true' == 1; // true (string to boolean) ?>
🔧 SECTION 3: Operators
📌 LESSON 3.1: Arithmetic Operators
| Operator | Operation | Example | Result |
|---|---|---|---|
| + | Addition | $a + $b | 19 |
| - | Subtraction | $a - $b | 11 |
| * | Multiplication | $a * $b | 60 |
| / | Division | $a / $b | 3.75 |
| % | Modulus | $a % $b | 3 |
| ** | Exponentiation | $a ** $b | 50625 |
<?php $x = 10; $y = 3; echo $x + $y; // 13 echo $x - $y; // 7 echo $x * $y; // 30 echo $x / $y; // 3.333... echo $x % $y; // 1 (remainder) echo $x ** $y; // 1000 (10³) ?>
📌 LESSON 3.2: Comparison Operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | Equal (value only) | $x == $y | true |
| === | Identical (value and type) | $x === $y | false |
| != | Not equal | $x != $y | false |
| !== | Not identical | $x !== $y | true |
| > | Greater than | $x > $z | true |
| < | Less than | $x < $z | false |
| >= | Greater than or equal | $x >= 10 | true |
| <= | Less than or equal | $z <= 5 | true |
<?php $num = 5; $text = '5'; var_dump($num == $text); // true (values equal) var_dump($num === $text); // false (types different) var_dump($num > 3); // true var_dump($num <= 5); // true ?>
📌 LESSON 3.3: Logical Operators
| Operator | Name | Example | Result |
|---|---|---|---|
| && | AND | $is_logged_in && $is_admin | false |
| || | OR | $is_logged_in || $is_admin | true |
| ! | NOT | !$is_admin | true |
| and | AND (low) | $is_logged_in and $has_permission | true |
| xor | XOR | $is_admin xor $has_permission | true |
<?php
$age = 25;
$has_id = true;
// Check both conditions
if ($age >= 18 && $has_id) {
echo 'You can enter';
}
// Check either condition
if ($age >= 18 || $has_id) {
echo 'Partial access';
}
?>📌 LESSON 3.4: String Operators
Concatenation (.) operator:
$first = 'Hello'
$second = 'World'
$combined = $first . ' ' . $second
Result: Hello World
Concatenation assignment (.=):
$message = 'Welcome'; $message .= ' to'; $message .= ' PHP!'; → Welcome to PHP!
<?php $greeting = 'Hello'; $name = 'Sarah'; $message = $greeting . ' ' . $name . '!'; echo $message; // Hello Sarah! $text = 'Start'; $text .= ' middle'; $text .= ' end'; echo $text; // Start middle end ?>
📌 LESSON 3.5: Assignment Operators
| Operator | Example | Equivalent to | Result |
|---|---|---|---|
| = | $x = 5 | $x = 5 | 5 |
| += | $x += 3 | $x = $x + 3 | 13 |
| -= | $x -= 2 | $x = $x - 2 | 8 |
| *= | $x *= 4 | $x = $x * 4 | 40 |
| /= | $x /= 2 | $x = $x / 2 | 5 |
| %= | $x %= 3 | $x = $x % 3 | 1 |
<?php $counter = 0; $counter += 5; // $counter = 5 $counter -= 2; // $counter = 3 $counter *= 4; // $counter = 12 $counter /= 3; // $counter = 4 ?>
📌 LESSON 3.6: Increment/Decrement
| Operator | Name | Example | Result |
|---|---|---|---|
| ++$x | Pre-increment | ++$count | 6 (increment then use) |
| $x++ | Post-increment | $count++ | 5 (use then increment) |
| --$x | Pre-decrement | --$count | 4 (decrement then use) |
| $x-- | Post-decrement | $count-- | 5 (use then decrement) |
<?php
$num = 5;
echo $num++; // 5 (then becomes 6)
echo $num; // 6
$num = 5;
echo ++$num; // 6 (immediately incremented)
echo $num; // 6
// Common use in loops
for ($i = 0; $i < 5; $i++) {
echo $i;
}
?>🤔 SECTION 4: Decision Making
📌 LESSON 4.1: If Statements
Age: 18
✅ You are eligible to vote.
if ($age >= 18) {
echo 'You are eligible to vote.';
}Another example:
Score: 85 → ✅ You passed with distinction!
📌 LESSON 4.2: If-Else
Score: 75 → ✅ You passed the exam!
if ($score >= 60) {
echo 'You passed!';
} else {
echo 'You need to study more.';
}Logged in: ❌ → Please log in to continue.
📌 LESSON 4.3: Elseif Ladder
Grade: 85 → Grade B - Very Good!
if ($grade >= 90) {
echo 'A';
} elseif ($grade >= 80) {
echo 'B';
} elseif ($grade >= 70) {
echo 'C';
} else {
echo 'F';
}Traffic light: yellow → ⚠️ Slow down!
📌 LESSON 4.4: Switch
Today is: Wednesday → Mid-week - you're doing great!
switch ($day) {
case 'Monday':
echo 'Start of week';
break;
case 'Friday':
echo 'Weekend coming';
break;
case 'Saturday':
case 'Sunday':
echo 'Weekend!';
break;
default:
echo 'Keep coding';
}Menu choice: 2 → You selected 'Edit Settings'
📌 LESSON 4.5: Ternary Operator
Age: 20 → Status: Adult
$status = ($age >= 18) ? 'Adult' : 'Minor';
Score 75 → Pass
Logged in: ✅ → Welcome back!
📌 LESSON 4.6: Null Coalescing
$_GET['user'] ?? 'Guest' → Guest
Chain: $user_color ?? $default_color ?? 'blue' → blue
// PHP 7+ null coalescing operator $name = $_POST['name'] ?? 'Anonymous'; // Instead of: $name = isset($_POST['name']) ? $_POST['name'] : 'Anonymous'; // Can chain multiple fallbacks $config = $user_setting ?? $default_setting ?? 'default';
Email: john@example.com
Phone: no phone provided
🔄 SECTION 5: Loops
📌 LESSON 5.1: For Loop
Count to 5:
for ($i = 1; $i <= 5; $i++) {
echo $i;
}Even numbers: 2 4 6 8 10
Countdown: 5 4 3 2 1 🚀
📌 LESSON 5.2: While Loop
While count is less than 6: 1 2 3 4 5
$count = 1;
while ($count <= 5) {
echo $count;
$count++;
}Sum of 1 to 10 = 55
📌 LESSON 5.3: Do-While
Executes at least once: 1 2 3
$num = 1;
do {
echo $num;
$num++;
} while ($num <= 3);Always runs once even if condition false.
📌 LESSON 5.4: Foreach Loop
Fruits:
- Apple
- Banana
- Orange
- Mango
- Grape
$fruits = ['Apple', 'Banana', 'Orange'];
foreach ($fruits as $fruit) {
echo $fruit;
}With keys: Name: John, Age: 25, Course: PHP
Doubled numbers: 2,4,6,8,10
📌 LESSON 5.5: Break & Continue
Break: 1 2 3 4 5 (stopped at 5)
Continue (odd numbers): 1 3 5 7 9
for ($i = 1; $i <= 10; $i++) {
if ($i % 2 == 0) continue; // Skip even
echo $i;
}📌 LESSON 5.6: Nested Loops
Multiplication table:
| 1 | 2 | 3 | 4 | 5 |
| 2 | 4 | 6 | 8 | 10 |
| 3 | 6 | 9 | 12 | 15 |
| 4 | 8 | 12 | 16 | 20 |
| 5 | 10 | 15 | 20 | 25 |
for ($i = 1; $i <= 5; $i++) {
for ($j = 1; $j <= 5; $j++) {
echo $i * $j . ' ';
}
echo '<br>';
}Pattern:
*
* *
* * *
* * * *
* * * * *
⚡ SECTION 6: Functions
📌 LESSON 6.1: Basic Functions
Hello from Krane Digital Hub!
Welcome to PHP Functions!
function sayHello() {
return 'Hello from Krane Digital Hub!';
}📌 LESSON 6.2: Parameters & Arguments
Welcome Sarah to PHP course!
Welcome John to Laravel course!
5 + 3 = 8
📌 LESSON 6.3: Return Values
Area of 10x5 rectangle: 50
User: John Doe (john@example.com)
📌 LESSON 6.4: Variable Scope
Inside function: I'm global
Inside function local: I'm local
Outside: I'm global
Counter: 1, 2, 3 (static)
📌 LESSON 6.5: Default Parameters
Name: John, Age: 25, Country: Nigeria
Name: Sarah, Age: 30, Country: Nigeria
Name: Mike, Age: 28, Country: Ghana
📌 LESSON 6.6: Type Declarations
add(5, 3): 8
formatName('John', 'Doe'): John Doe
📌 LESSON 6.7: Anonymous Functions
Hello, Sarah!
Squared numbers: 1, 4, 9, 16, 25
📌 LESSON 6.8: Arrow Functions
Even numbers: 2, 4, 6
Squared: 1, 4, 9, 16, 25, 36
📚 SECTION 7: Arrays
📌 LESSON 7.1: Indexed Arrays
- Index 0: Apple
- Index 1: Banana
- Index 2: Orange
- Index 3: Mango
- Index 4: Grape
$fruits[0] = Apple
$fruits[2] = Orange
Array length: 5 items
📌 LESSON 7.2: Associative Arrays
| Name: | Sarah Johnson |
| Age: | 23 |
| Course: | PHP Masterclass |
| Grade: | A |
| Active: | Yes |
📌 LESSON 7.3: Multidimensional Arrays
Beginner Level
| Course | Duration | Price |
|---|---|---|
| PHP Basics | 4 weeks | $99.99 |
| HTML & CSS | 3 weeks | $79.99 |
| JavaScript Intro | 4 weeks | $99.99 |
Intermediate Level
Advanced Level
🏗️ SECTION 18: Building a Complete Application
📌 LESSON 18.1: Student Portal - Complete Demo
👤 Student Profile
Name: Alex Johnson
Email: alex@example.com
Joined: 2025-03-15
Courses: 4
Average Progress: 31.3%
Course Progress:
PHP Basics:
MySQL Fundamentals:
Laravel Introduction:
API Development:
✅ Enrolled in PHP Basics
✅ Enrolled in MySQL Fundamentals
✅ Enrolled in Laravel Introduction
✅ Enrolled in API Development
📊 Progress updated to 75%
📊 Progress updated to 30%
📊 Progress updated to 15%
📊 Progress updated to 5%
✅ Congratulations! You've completed PHP Basics!