Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

conditionals

Conditionals: if, elseif, else

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Conditionals: if, elseif, else: the syntax, APIs, and habits you need before advancing in PHP.

Teams ship Conditionals: if, elseif, else on every PHP codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Conditionals: if, elseif, else in contexts like: LAMP/LEMP stacks, Laravel apps, WordPress themes/plugins, and shared hosting.

Write PHP in the editor and click Run on server—the dev runner executes your script and returns stdout/stderr (set LEARNING_RUNNER_ENABLED=true locally).

When you can explain the previous lesson's ideas without copying starter code.

Branch logic with if, elseif, and else. PHP also offers match (PHP 8+) as an expression-based alternative to long switch blocks.

if / elseif / else

if ($score >= 90) {
    $grade = 'A';
} elseif ($score >= 80) {
    $grade = 'B';
} else {
    $grade = 'C';
}

Truthy and falsy

Falsy values: false, 0, 0.0, '', '0', null, empty arrays. Prefer explicit checks for business rules—do not rely on loose truthiness for money or permissions.

match expression (PHP 8+)

$label = match ($status) {
    'draft' => 'Draft',
    'published' => 'Live',
    default => 'Unknown',
};

Self-check

  1. When is elseif evaluated?
  2. Why prefer === in permission checks?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • elseif readability?
  • Match vs switch?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump