Convert print_r output to PHP array

Input data

This form allows you convert print_r to PHP Array, paste or upload your print_r output below:


Your result can be seen below.

Result of print_r conversion to PHP Array


Move to "Paste Code" for Save it

FAQ

Why convert print_r to PHP array?

Very often, when working with arrays in PHP, you may need to output an intermediate array via print_r to check its elements, and then you may need to convert the print_r output back to an array to continue writing code to process this array. Thus, this is mostly necessary when developing and debugging code.

How to convert print_r to PHP array?

Just paste the output from print_r into the textarea above and click to the button "Convert" and you'll get a PHP array in the next textarea.

How to recreate PHP array from print_r output?

To convert print_r to an array, you need to parse the text using regular expressions. You can find an example solution here https://www.php.net/manual/ru/function.print-r.php#121259

What is print_r in PHP?

print_r() prints information about a variable. If string, integer, or float is given, the value itself is printed. If array is given, the values will be presented in a format showing keys and values.

Example of print_r conversion to PHP Array

Before:
Array
(
    [website] => Array
        (
            [domain] => wtools.io
            [title] => Online Web Tools
        )

    [string] => some text
    [integer] => 1
    [float] => 2.3
    [subArray] => Array
        (
            [0] => Hello World.
        )

)
After:
[
  'website' => [
    'domain' => 'wtools.io',
    'title' => 'Online Web Tools',
  ],
  'string' => 'some text',
  'integer' => 1,
  'float' => 2.3,
  'subArray' => [
    0 => 'Hello World.',
  ],
]
After the conversion, you can apply the PHP array to your project or use it for some other purpose.
Performnate

Did you like this tool? You can donate to us. This will help us improve our free web tools.

Paypal