JSON to PHP Array Converter
Convert JSON to PHP array syntax instantly. Supports nested associative and indexed arrays, all PHP data types, and both short [] and long array() notations.
Features
đ Idiomatic PHP
- Associative arrays with => syntax
- Nested array support
- Proper single-quote string escaping
- Optional $data variable assignment
đŖ Type-Accurate Output
- Strings in single quotes
- Numbers as PHP numeric literals
- Booleans as true / false
- JSON null mapped to PHP null
âī¸ Flexible Options
- Short [] or long array() syntax
- Toggle <?php tag inclusion
- Toggle variable assignment
- Download as .php file
PHP Array Guide
PHP Array Syntax
PHP supports both short array syntax (available since PHP 5.4) and the traditional array() function. Both are equivalent; short syntax is preferred in modern PHP.
// Short syntax (PHP 5.4+)
$data = [
'name' => 'Alice',
'age' => 30,
];
// Long syntax (all PHP versions)
$data = array(
'name' => 'Alice',
'age' => 30,
);
When to use PHP arrays generated from JSON
Converting JSON into a PHP array literal is useful for configuration files, test fixtures and seed data, where you want the data in version control as native PHP rather than parsed at runtime.
Tips and common pitfalls
- For data that changes often, keep it as JSON and load it with
json_decode($json, true)instead of hard-coding an array. - Always pass
JSON_THROW_ON_ERRORtojson_decodeso invalid JSON throws an exception instead of returningnullsilently. - Large integers beyond PHP_INT_MAX become floats. Use
JSON_BIGINT_AS_STRINGto keep them exact. - A config file can simply
return [...]; load it with$config = require "config.php";.
More questions
Associative array or object from json_decode?
Passing true returns associative arrays, which are easier to manipulate and serialize back. Objects (stdClass) are fine for read-only access with arrow syntax.
How do I turn the array back into JSON?
Use json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) for readable output.