YAML to PHP Converter
Convert YAML to PHP associative array syntax
YAML Input
PHP Output
Paste your YAML on the left and the PHP code shows up here.
Or drop a file on this box, , or .
What is YAML to PHP Converter?
This tool converts YAML data structures into PHP associative arrays. YAML is widely used in configuration files for frameworks like Symfony and Laravel, while PHP arrays are the native data structure for PHP applications. This converter bridges the gap, letting you generate PHP array syntax from any YAML file.
PHP's array syntax uses ['key' => 'value'] notation for associative arrays. Nested YAML structures become nested PHP arrays, lists become indexed PHP arrays, and scalar values are converted to their PHP equivalents. According to the PHP Manual, arrays are the most versatile data structure in PHP, making this conversion essential for PHP developers working with YAML configs.
This converter generates PHP associative arrays from YAML mappings. PHP types are inferred automatically: strings are quoted, numbers are unquoted, and booleans use true/false keywords. For runtime YAML parsing, the Symfony YAML component is the most widely used PHP library for the job.
How to Convert YAML to PHP
Follow these steps to convert your YAML data to PHP array syntax.
Paste or Upload Your YAML
Start with YAML in the left editor, typed, pasted or uploaded. Sample brings in a product record with a price, a stock flag and a tag list. Here is a smaller config with a database block and a feature list:
database:
host: localhost
port: 3306
name: myapp
features:
- logging
- caching Click Convert
The PHP is regenerated as you type. The config above becomes a $data = [...] assignment under an opening <?php tag: database turns into a keyed array where port stays the integer 3306, and features becomes a plain list holding logging and caching. Every element ends with a trailing comma, which PHP accepts.
Copy or Download the PHP Code
Copy puts the generated PHP on the clipboard; Download saves it as a .php file. Either way it pastes straight into your PHP application.
When You'd Use This Tool
Framework Configuration
Convert Symfony or Laravel YAML configuration files to PHP arrays when migrating to PHP-native configuration formats.
Seed Data
Convert YAML data fixtures to PHP arrays for database seeding scripts or test fixtures in PHPUnit.
API Integration
Convert YAML API response schemas to PHP array structures for building request/response handlers.
Config Migration
Migrate YAML-based application config to PHP arrays when switching from a YAML-based framework to vanilla PHP.
Frequently Asked Questions
How are YAML types mapped to PHP?
Strings become single-quoted PHP strings, numbers remain as-is, booleans become true/false, null becomes null, lists become indexed PHP arrays, and mappings become associative arrays.
Does it handle nested YAML structures?
Yes. Nested YAML mappings become nested PHP associative arrays. Deep nesting is fully supported.
Can I use the output directly in PHP?
Yes. The generated code uses PHP 5.4+ short array syntax []. You can assign it to a variable or return it from a function.
Do you keep a copy of the YAML I turn into a PHP array?
No copy is kept, because nothing is sent. The YAML is parsed in this tab and the array literal is built right beside it. Integers longer than a JavaScript number can hold, like a 19-digit ICCID, are written out digit for digit instead of being rounded.
What about YAML anchors and aliases?
Anchors and aliases are resolved during parsing, the same way js-yaml resolves them in Node, so the PHP output contains the fully resolved values.
Related YAML Tools
Explore other YAML conversion tools: