🚀 KRANE DIGITAL PROGRAMMING ACADEMY

Empowering Dreams

Empowering the next generation of PHP developers

18
Sections
72
Lessons
100+
Examples
🎓
Certificate

📖 Course Contents

Click any section to jump directly to that lesson

📘

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:

  1. Browser requests a .php file from your server
  2. Server reads the PHP code and processes it
  3. Server executes any instructions (database queries, calculations, etc.)
  4. Server generates HTML based on the PHP code
  5. Server sends ONLY the HTML to the browser
  6. 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

TypeExampleValueDescription
String$name = "John"JohnText data
Integer$age = 2525Whole numbers
Float$price = 99.9999.99Decimal numbers
Boolean$is_active = truetruetrue/false
Array$skills = [...]PHP, MySQL, JavaScriptCollection of values
NULL$data = nullnullNo 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

OperatorOperationExampleResult
+Addition$a + $b19
-Subtraction$a - $b11
*Multiplication$a * $b60
/Division$a / $b3.75
%Modulus$a % $b3
**Exponentiation$a ** $b50625
<?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

OperatorMeaningExampleResult
==Equal (value only)$x == $ytrue
===Identical (value and type)$x === $yfalse
!=Not equal$x != $yfalse
!==Not identical$x !== $ytrue
>Greater than$x > $ztrue
<Less than$x < $zfalse
>=Greater than or equal$x >= 10true
<=Less than or equal$z <= 5true
<?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

OperatorNameExampleResult
&&AND$is_logged_in && $is_adminfalse
||OR$is_logged_in || $is_admintrue
!NOT!$is_admintrue
andAND (low)$is_logged_in and $has_permissiontrue
xorXOR$is_admin xor $has_permissiontrue
<?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

OperatorExampleEquivalent toResult
=$x = 5$x = 55
+=$x += 3$x = $x + 313
-=$x -= 2$x = $x - 28
*=$x *= 4$x = $x * 440
/=$x /= 2$x = $x / 25
%=$x %= 3$x = $x % 31
<?php
$counter = 0;
$counter += 5;  // $counter = 5
$counter -= 2;  // $counter = 3
$counter *= 4;  // $counter = 12
$counter /= 3;  // $counter = 4
?>

📌 LESSON 3.6: Increment/Decrement

OperatorNameExampleResult
++$xPre-increment++$count6 (increment then use)
$x++Post-increment$count++5 (use then increment)
--$xPre-decrement--$count4 (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:

1 2 3 4 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:

12345
246810
3691215
48121620
510152025
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

CourseDurationPrice
PHP Basics4 weeks$99.99
HTML & CSS3 weeks$79.99
JavaScript Intro4 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:

75%

MySQL Fundamentals:

30%

Laravel Introduction:

15%

API Development:

5%

✅ 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!

🎯 Complete all courses with 100% progress to earn your certificate!

📌 LESSON 18.2: Course Catalog System

Categories:

Programming Database Framework Web Development Security

PHP Basics

Beginner

Learn PHP from scratch - variables, loops, functions

⏱️ 4 weeks

👥 2 students

📁 Programming

⭐⭐⭐⭐☆ (1)

$99.99

👨‍🏫 About the Author

👔
Udoinyang, M. Clement
aka Mr. Krane

📋 Biography:

Mr. Krane is a passionate software developer, web designer, teacher, and businessman...

🎓 Education:

  • PC Support - Springwood Information Technology, Uyo
  • Computer and Robotics Education - University of Uyo, Nigeria

📍 Origin: Ikot Ekpene LGA, Akwa Ibom State, Nigeria

💼 Professional Roles:

👨‍💻 Software Developer 🎨 Web Designer 📚 Teacher 💼 Businessman 🏆 CEO, Krane Digital Hub

🎯 Hobbies & Interests: Music, Chess, Coding, and Watching Movies

💡 Teaching Philosophy: "Every expert was once a beginner..."

📞 Contact: WhatsApp | Facebook | Instagram

"Empowering Dreams through Code"

- Mr. Krane

💬 Chat on WhatsApp
⬆️ Top 📥 Download PDF 🌐 Website