Skip to content
Learn Netverks

Lesson

Step 13/36 36% through track

associative-arrays

Associative arrays

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

This lesson

This lesson teaches Associative arrays: the syntax, APIs, and habits you need before advancing in PHP.

Teams ship Associative arrays on every PHP codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Associative arrays 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.

Associative arrays use string (or int) keys—like JavaScript objects or Python dicts. They model records, config maps, and lookup tables.

Syntax

$user = [
    'id' => 1,
    'name' => 'Ada',
    'email' => 'ada@example.com',
];
echo $user['name'];

Checking keys

array_key_exists('email', $user) or isset($user['email'])isset returns false if the value is null.

Mixed arrays

PHP allows numeric and string keys in one array, but keep structures predictable for teammates and static analysis tools.

Important interview questions and answers

  1. Q: Array vs object in PHP?
    A: Arrays are built-in ordered maps; objects are instances of classes with methods and visibility—use objects when behavior belongs with data.

Self-check

  1. How do you read the email key safely if it might be missing?
  2. Can associative arrays preserve insertion order?

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

  • Key type limits?
  • isset vs array_key_exists?

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