PHP Fatal error: Uncaught Error: Cannot use a scalar value as an array
Code assigned to $x[...] where $x holds a number, string or boolean.
Cannot use a scalar value as an arrayUncaught Error Cannot use a scalar value as an array Meaning
PHP 7.1+ throws once a variable holds a scalar (true, 1, 'text') and you try to append or index. false/null auto-create arrays only in some cases.
Common causes
- Variable previously assigned a scalar (e.g.,
$a = 1; $a[] = 2) - Function returning false on failure used as an array
- Reusing a variable name
- Config value set as string, treated as array
⚡ Quick fix
- Initialise
$x = []before use - Check function return values
- Rename variables
Detailed fix by platform
PHP
$items = []; $items[] = $row;
How to diagnose
- Type — var_dump before use?
- Reuse — Variable overwritten?
- Return — false on failure?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 2 Dec 2026