Format PHP Array
Paste a PHP array assignment and get consistent comma spacing, with each statement on its own line. This is a light tidy-up: it does not put one array element per line. If you need that, plan on a manual edit or a dedicated formatter.
How to format a PHP array
-
1
Paste the array code
Enter the full statement, for example the line that assigns the array to a variable.
-
2
Leave the indent as is
The indent only affects curly braces, so an array on its own is not changed by it.
-
3
Continue to the result
Open the formatted code.
-
4
Copy the output
Check the array still looks right, then copy it.
What happens to an array
The formatter looks at commas and semicolons. Each comma is followed by exactly one space, and each semicolon ends a line. Square brackets, parentheses and the => arrow are left as written.
Input:
<?php $colors=["red","green","blue"];$sizes=[1,2,3];
Result:
<?php $colors=["red", "green", "blue"];
$sizes=[1, 2, 3];
Two arrays, two lines, readable commas.
Nested and associative arrays
Associative arrays work the same way. This input:
<?php $user=["id"=>1,"name"=>"Ana","roles"=>["admin","editor"]];
comes back as:
<?php $user=["id"=>1, "name"=>"Ana", "roles"=>["admin", "editor"]];
The nesting is untouched and everything stays on one line, because there are no semicolons or curly braces inside the array to trigger a break. Spaces around => are not added.
What it will not do
- It will not start a new line after each element or indent array contents.
- Square brackets and parentheses never add an indentation level.
- Commas inside quoted strings also get a space, so a value such as
"1,5"becomes"1, 5". Review any string that contains commas before you copy the result. - Curly braces, for example in a function that returns the array, are put on separate lines and indented as usual.
A typical use case
Configuration arrays copied from a log, a database field or an API response often arrive with commas jammed against the next value. Running them through this page makes each value easier to tell apart, and gives you a version that is easier to compare by eye with a second array. If you need one key per line, split the result at the commas in your editor. Use find and replace to add a line break after each comma.
Check the result
Count the elements before and after. The number of values must be the same, because the tool only adds spaces after commas. If the count changed, a string contained a comma that you did not expect.
Short arrays and long arrays
Short lists such as [1,2,3] are clear after a single pass. Very long arrays remain one long line, because nothing in them marks a break point. For those, formatting in an editor that understands PHP is the better route. For quick checks and small configuration snippets, this page is enough.
Frequently Asked Questions
No. It only adds a space after commas and breaks lines at semicolons and braces.
No. The arrow keeps whatever spacing you pasted.
Yes. The tool treats both the same, since it only looks at commas, semicolons and braces.
The comma rule runs over the whole text before strings are recognised. Restore the original string value by hand after copying.
Related Tools
Color Wheel Explorer
Explore the colour wheel interactively. Rotate harmonies, compare HSL vs RYB, spot complementary and triadic pairs in real time.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
Random Phone Number Generator
Generate 1 to 50 fictional phone numbers from officially reserved ranges for the US, Canada, UK, Australia or Germany.
Placeholder Image Generator
Create a 1–4000 px placeholder with custom colors and text, download it as PNG, or copy a URL and HTML image tag.
GitHub Profile README Generator
Build the README.md for your GitHub profile page (the username/username repo) with tagline, skills, stats cards and language breakdown.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
Tool available in other languages
- Formatera PHP-array [SV]
- จัดรูปแบบอาร์เรย์ PHP [TH]
- تنسيق مصفوفة PHP [AR]
- Formater un tableau PHP [FR]
- PHP 배열 포맷하기 [KO]
- Een PHP-array opmaken [NL]
- Formatuj tablicę PHP [PL]
- PHP-Array formatieren [DE]
- Format Array PHP [ID]
- Định dạng mảng PHP [VI]
- PHP 配列を整形する [JA]
- Formatear un array de PHP [ES]
- Formatar array PHP [PT]
- PHP Dizisini Biçimlendirin [TR]
- 格式化 PHP 数组 [ZH]
- Formattare un array PHP [IT]
- Форматирование массива PHP [RU]