# PHP Fatal error: Uncaught Error: Cannot use a scalar value as an array

**Code:** `scalar value as an array` · **Category:** PHP · **Seen on:** PHP

Code assigned to `$x[...]` where `$x` holds a number, string or boolean.

## 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

1. Initialise `$x = []` before use
2. Check function return values
3. Rename variables

## Detailed fix by platform

### PHP

1. `$items = []; $items[] = $row;`

## How to diagnose

1. **Type** — var_dump before use?
2. **Reuse** — Variable overwritten?
3. **Return** — false on failure?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/php-cannot-use-scalar-value-as-array)
