Overview
Introduction
PHP config files, especially Laravel-style ones, are usually plain array literals rather than YAML. When you need to bring that data into a YAML-based pipeline, a CI file, a Kubernetes ConfigMap, documentation, converting a PHP array literal into YAML by hand means retyping every nested key and re-indenting by eye.
This tool parses a PHP array literal directly and emits the equivalent YAML document, saving that manual transcription.
What Is PHP Array to YAML Converter?
A PHP-to-YAML converter with a small hand-written parser for PHP's array literal syntax: `'key' => value` pairs (or bare positional values) inside `[...]` or `array(...)`, nested to any depth.
The parsed structure, plain PHP scalars, arrays, and associative arrays, is handed to this category's standard YAML writer, the same one used by every other converter in this category, to produce the final YAML output.
How PHP Array to YAML Converter Works
The input is first stripped of an optional `<?php` tag and `$variable = ... ;` wrapper, then parsed with a small recursive-descent parser purpose-built for PHP's array literal grammar: quoted strings, numbers, `true`/`false`/`null`, and nested `[...]`/`array(...)` blocks with `=>` keys.
Once parsed into a plain JS value, an array's entries become a YAML sequence only if every key is absent or exactly forms the contiguous index sequence "0", "1", "2", ...; otherwise it becomes a YAML mapping. The result is then serialized as block-style YAML.
When To Use PHP Array to YAML Converter
Use it when migrating configuration data that currently lives in a PHP array literal into a YAML-based system or pipeline.
It's also handy for quickly previewing what a PHP config snippet would look like as YAML during a migration or code review.
Often used alongside YAML to PHP Array Converter, YAML to JSON Converter and YAML Formatter & Prettifier.
Features
Advantages
- Accepts both PHP array syntaxes (`[...]` and `array(...)`) and full snippets with the `<?php`/assignment wrapper included.
- Produces the exact inverse structure of this category's YAML to PHP Array converter, so round-tripping through both tools reproduces the original shape.
- Correctly distinguishes positional (list-like) arrays from associative ones using the same contiguous-index rule PHP itself relies on.
- Runs entirely client-side, so array contents never leave your browser.
Limitations
- Only array literals are understood, not arbitrary PHP expressions, function calls, variables, or string interpolation inside double-quoted strings beyond the handful of escape sequences that are recognized.
- PHP-specific numeric edge cases (very large integers, octal/hex literals) aren't specially handled beyond standard decimal integer and float parsing.
- The output always uses this category's standard block-style YAML formatting; flow style or custom indentation isn't configurable from this tool.
Examples
Best Practices & Notes
Best Practices
- Paste PHP straight from a config file, including the `<?php` tag and variable assignment, the wrapper is stripped automatically.
- Run the result through YAML Formatter afterward if you need a specific indent width other than the default.
- Round-trip through YAML to PHP Array afterward to sanity-check that the conversion preserved the structure you expect.
Developer Notes
The parser is a small hand-written recursive-descent implementation covering exactly the subset of PHP array literal syntax that `yamlToPhpArray` itself produces (short and long array syntax, quoted string/numeric/boolean/null scalars, nested arrays), not a general PHP expression evaluator. Parsing then hands off to this category's shared `toBlockYaml` writer rather than any hand-rolled YAML serialization.
PHP Array to YAML Converter Use Cases
- Migrating a PHP config array into a YAML-based CI, deployment, or documentation pipeline
- Converting Laravel or Symfony-style config arrays into YAML for a different framework
- Previewing what a PHP array literal would look like as YAML during a code review or migration
- Generating YAML fixtures from PHP array literals used elsewhere in a project
Common Mistakes
- Pasting arbitrary PHP code (function calls, variables, ternaries) instead of a plain array literal, only literal array syntax is understood.
- Assuming numeric-looking PHP string keys stay quoted the same way in the output, YAML's own quoting rules decide how each scalar is written, not the original PHP quoting style.
- Forgetting that positional PHP arrays become YAML sequences while associative ones become mappings, mixing the two in one array can produce a mapping with numeric-looking string keys instead of a sequence.
Tips
- If the source array is very large, consider Truncate YAML on the output afterward to get a smaller representative sample.
- Use YAML to PHP Array to convert back and confirm a clean round trip after any manual edits.
- Pair with YAML Flattener if you need a flat key-path view of the converted structure instead of nested YAML.