All Tools View Categories Blog About Contact Privacy
CompressPrivate
Compress Anything.
Images · PDF · Video · Audio · Docs
🔒 100% Private ⚡ Free Forever ☁️ No Uploads
Compress Free

Convert XML to a PHP Array

Generate a PHP array literal from XML — perfect for config files and caches. Attributes, text and nested elements map to array keys.

Input
Output

About Convert XML to a PHP Array

Convert XML to a PHP Array produces a clean PHP array literal you can paste straight into PHP code. Elements become nested arrays, repeated elements become indexed arrays, attributes are stored under a configurable key and text under another.

Features

  • var_export-style, syntax-valid PHP
  • Short array syntax [ ] option
  • Configurable attribute and text keys
  • Auto number detection
  • Copy-and-paste ready
  • How to Use

  • Paste an XML document.
  • Pick array style, variable name and key prefixes.
  • Copy the PHP code or download it as a .php file.
  • Examples

    The sample becomes $data = array('catalog' => array('product' => array(0 => array('@id' => 'p1', …))));

    Benefits

  • Bootstrap PHP configs and fixtures fast
  • Type-safe array literals
  • Deterministic output for caching
  • Frequently Asked Questions

    Is my XML sent to a server?
    No. Everything runs locally in your browser. Your data is never uploaded, stored or logged.
    Can I download the result?
    Yes — use the Download button below the output area, or Print / Save PDF for a printable copy.

    More XML Tools

    View All