Undefined array key 🐘 PHP

Warning: Undefined array key / Undefined index

Your code reads an array key that doesn’t exist — common with $_GET, $_POST and decoded JSON.

Seen on: PHP

Meaning

PHP 8 reports “Undefined array key”; PHP 7 said “Notice: Undefined index”. It’s a warning, not fatal, but the value is null and often breaks logic downstream — and printed warnings can corrupt JSON or headers.

Common causes

  • Form field not submitted (unchecked checkbox, wrong name)
  • Query parameter missing
  • API response shape differs from expectations
  • Typos in key names

⚡ Quick fix

  1. Use the null coalescing operator: $_GET['page'] ?? 1
  2. Check with isset() / array_key_exists()
  3. Validate input up front

Detailed fix by platform

PHP

  1. Defaults with ??:
    php
    $page  = (int) ($_GET['page'] ?? 1);
    $email = trim($_POST['email'] ?? '');

How to diagnose

  1. Key — Which key, at which line?
  2. Source — Is the input actually sent?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.