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
- Use the null coalescing operator:
$_GET['page'] ?? 1 - Check with
isset()/array_key_exists() - Validate input up front
Detailed fix by platform
PHP
- Defaults with ??:php
$page = (int) ($_GET['page'] ?? 1); $email = trim($_POST['email'] ?? '');
How to diagnose
- Key — Which key, at which line?
- 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026