Question: I have an array:

```
$a = array('foo' => 'fooMe');

```

and I do:

```
print_r($a);

```

which prints:

```
Array ( [foo] => printme )

```

Is there a function, so when doing:

```
needed_function('    Array ( [foo] => printme )');

```

I will get the array `array('foo' => 'fooMe');` back?

Answer: 
you cannot do this with `print_r`,  

`var_export` should allow something similar, but not exactly what you asked for

<http://php.net/manual/en/function.var-export.php>

```
$val = var_export($a, true);
print_r($val);
eval('$func_val='.$val.';');

```
This is how I interpreted the question:

```
function parsePrintedArray($s){
    $lines = explode("\n",$s);
    $a = array();
    foreach ($lines as $line){
        if (strpos($line,"=>") === false)
            continue;
        $parts = explode('=>',$line);
        $a[trim($parts[0],'[] ')] = trim($parts[1]);
    }
    return $a;
}

```

Works for both objects and arrays:

```
$foo = array (
    'foo' => 'bar',
    'cat' => 'dog'
);

$s = print_r($foo,1);
$a = parsePrintedArray($s);
print_r($a);

```

Output:

```
Array
(
    [foo] => bar
    [cat] => dog
) 

```

doesnt work on nested arrays, but simple and fast.