PHP Array Converter
Generate a PHP array from pasted values.
Build the PHP array
PHP Array Converter
// Your converted output will appear here.
Pick short [] or classic array() syntax, and single or double quotes — the escaping rules differ between the two, and this tool applies the right set for each.
How to use the PHP Array Converter
Paste your values
One per line by default. Change the delimiter for comma or tab separated input.
Choose the array syntax
Short [] for anything on PHP 5.4 or newer. array() when the codebase or its style guide still expects it.
Choose the quote style
Single quotes are literal. Double quotes interpolate variables and interpret escape sequences — pick them only when you need that.
PHP Array Converter examples
Short array syntax
Input
admin editor subscriber
Output
$roles = [ 'admin', 'editor', 'subscriber' ];
Classic array() syntax
Input
admin editor
Output
$roles = array( 'admin', 'editor' );
Still required on PHP 5.3 and older, and still common throughout WordPress and Drupal.
A value containing a dollar sign
Input
$total plain
Output
$labels = [ "\$total", "plain" ];
With double quotes selected, the dollar sign is escaped so PHP does not try to interpolate a variable.
Working with php array converter
Single and double quotes escape differently
Inside single quotes PHP recognises exactly two escapes: an escaped apostrophe and an escaped backslash. Everything else is literal, newline sequences included — so "escaping" a newline there would silently insert a backslash and the letter n. Inside double quotes PHP interpolates variables and interprets escape sequences, so the dollar sign and brace must be escaped. This tool applies each rule set correctly rather than using one escaper for both.
Short syntax versus array()
[] has been available since PHP 5.4 and is the modern default. array() is not deprecated and still appears across WordPress, Drupal and older Laravel code. If you are pasting into an existing file, match what is already there — mixed syntax in one file is the kind of thing that gets flagged in review.
Reading the array back
For a list of values, in_array($needle, $roles, true) is the membership test — pass true so it compares types too, otherwise PHP's loose comparison can match 0 against a non-numeric string. If you test membership often, array_flip() plus isset() is the faster shape.
Popular text conversion tools
JavaScript Array Converter
Turn a list or string into a JavaScript array with const, let or var, single, double or template quotes, and automatic number and boolean detection.
CSV to Array Converter
Parse real CSV with quoted commas, escaped quotes and headers into arrays of rows or objects, then output JSON, JavaScript, Python or PHP.
Text to JSON Array Converter
Use this free online text to JSON array converter to turn lines, lists, TXT files, or delimited values into valid pretty-printed or minified JSON.
String to Array Converter
Use this free online string to array converter to split text by commas, delimiters, whitespace, regex, or visible characters and copy matching code.
PHP Array Converter FAQs
PHP Array Converter
Generate a PHP array from pasted values. Pick short [] or classic array() syntax, and single or double quotes — the escaping rules differ between the two, and this tool applies the right set for each.