PHP array output appears here
Paste JSON and click Convert// convert json to clean php array output
Convert JSON objects and arrays to clean PHP array syntax instantly. Supports nested structures, type preservation, and multiple output styles.
PHP array output appears here
Paste JSON and click ConvertEnter your JSON object or array in the input field on the left.
Select short [] or long array() syntax. Set your preferred variable name.
Click Convert, then copy the PHP array or download it as a .php file.
This tool converts any valid JSON structure into properly formatted PHP array syntax. It preserves all data types — strings, integers, floats, booleans, and nulls — and correctly handles both indexed arrays and associative arrays with string keys.
Short syntax uses square brackets [] and was introduced in PHP 5.4. Long syntax uses the array() function and works in all PHP versions. Both produce identical arrays at runtime — the difference is purely cosmetic. Most modern PHP codebases prefer the shorter [] form.
Yes. Nested JSON objects and arrays are recursively converted to nested PHP arrays with proper indentation. Each level uses 4 spaces of indentation so the output is immediately readable and PSR-2 compliant.
JSON strings become PHP single-quoted strings with escaped characters. JSON numbers become PHP integers or floats. JSON true/false become PHP true/false. JSON null becomes PHP null. Arrays stay as indexed arrays; objects become associative arrays.
Single quotes and backslashes inside string values are automatically escaped with a backslash, so the generated PHP code is always syntactically valid. Unicode characters are preserved as-is since PHP strings are byte arrays.
Yes. The conversion runs entirely in your browser using JavaScript, so there are no server-side file size limits. Very large files (10 MB+) may take a moment to render but will work correctly. The download button lets you save the output directly to a .php file.
The output uses 4-space indentation and trailing commas after the last element, which aligns with PSR-12 style for array declarations. The variable assignment line follows standard PHP conventions. You can paste the output directly into any PHP file without reformatting.
No. All conversion logic runs locally in your browser using JavaScript. Your JSON data never leaves your machine and is never sent to any server. This makes the tool safe for sensitive configuration files and private data.
Yes. There is a variable name field at the top of the tool. Change it to any valid PHP variable name (letters, numbers, underscores — no leading numbers) and the output will use that name in the assignment: $yourName = [...];.
PHP developers frequently need to work with data in both JSON and native PHP array formats. Whether you're migrating configuration files, seeding a database, adapting a REST API response for internal use, or writing unit tests, converting JSON to PHP array syntax by hand is tedious and error-prone. This free online tool automates the entire process in milliseconds.
💡 Looking for premium JavaScript plugins and scripts? MonsterONE offers unlimited downloads of templates, UI kits, and developer assets — worth checking out.
A PHP array is one of the language's most versatile data structures. Unlike arrays in strictly-typed languages, a PHP array can serve as a list (indexed by consecutive integers) or a map (indexed by arbitrary string or integer keys). Internally, PHP arrays are ordered hash maps, which means they maintain insertion order while providing O(1) key lookups.
You can declare an array in PHP using two equivalent syntaxes:
// Short syntax (PHP 5.4+) — recommended
$config = [
'host' => 'localhost',
'port' => 3306,
];
// Long syntax — works in all PHP versions
$config = array(
'host' => 'localhost',
'port' => 3306,
);
JSON has become the lingua franca of data interchange on the web. Configuration files, API payloads, database exports, and frontend-backend communication all commonly use JSON. When that data needs to live inside a PHP application — as a hardcoded config, a fixture for testing, or a seed file — it needs to be expressed as native PHP array syntax rather than a JSON string that must be parsed at runtime.
Converting manually is tedious. Consider a 200-line JSON config file: you would need to replace every { with [, add => between keys and values, wrap all keys in quotes with the right escaping, and change null, true, and false to lowercase PHP keywords. One typo breaks everything. This tool does all of that in one click.
The converter parses your JSON input using the browser's built-in JSON.parse(), which validates the syntax and produces a JavaScript object tree. It then walks that tree recursively and generates properly indented PHP code:
{}) → PHP associative arrays with 'key' => value pairs.[]) → PHP indexed arrays with bare values.int or float depending on whether a decimal point is present.true / false.null.The tool supports two PHP array syntaxes. Short syntax ([]) was introduced in PHP 5.4 and is the modern standard. It is more concise, easier to read, and used by virtually all modern PHP frameworks including Laravel, Symfony, and WordPress (for new code). Long syntax (array()) is compatible with PHP versions before 5.4, though those are now far beyond end-of-life. Choose long syntax only if you are working with a legacy codebase that specifically requires it.
Real-world JSON is rarely flat. API responses, configuration files, and database exports often contain deeply nested objects and arrays. This converter handles arbitrary nesting depth. Each level of nesting adds one level of 4-space indentation, producing output that is immediately readable and diff-friendly in version control.
One subtle challenge when converting between JSON and PHP is floating-point precision. JSON numbers like 1.10 may be represented internally as 1.1000000000000001 due to IEEE 754 floating-point arithmetic. The converter trims trailing zeros to produce clean output. Similarly, strings containing single quotes or backslashes are escaped with a backslash so the output is always syntactically valid PHP without requiring double-quote strings.
Empty JSON objects ({}) and empty arrays ([]) become PHP [] or array() on a single line rather than spanning multiple lines unnecessarily.
When using the generated PHP arrays in your codebase, follow these conventions for maintainable code. Use const for static configuration arrays that never change at runtime — this avoids variable reassignment accidents. Trailing commas after the last array element are considered best practice in PHP because they produce cleaner Git diffs when new items are added. Keep deeply nested arrays in separate named variables rather than inlining everything, which makes the code easier to read and refactor. For large data sets, consider whether a PHP array is actually the right data structure, or whether a dedicated PHP class or database table would serve better.