If you want it to be disassembled, you can use
var_export - var_export or returns a syntax string representation of a variable
Example
file_put_contents('array.txt', var_export($array, TRUE));
If you want this to be similar to your question, you pass TRUE as the second parameter to print_r :
file_put_contents('array.txt', print_r($array, TRUE));
EDIT you mentioned in the comments that you want the array to be converted to a CSV file. This is harder. Your array is nested, while the CSV file is basically one small array, for example
array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn');
will be equivalent to a CSV file, where the first lines are the keys of the array and the second line are the values.
k1; k2; ...; kn v1; v2; ...; vn
Single dims arrays are usually located inside another array, so you have a collection like this:
array( array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn'), array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => 'vn') );
Here you need to first get the keys, and then extract only the values ββfrom the array for subsequent lines, for example.
k1; k2; ...; kn v1; v2; ...; vn v1; v2; ...; vn
The problem is that your array is nested even deeper. Where would you put the address array? The only possible approach would be to go through the array and extract only those keys and values ββthat contain the scalar type, and linearize any nested arrays, for example.
array( array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => array( 'skn' => 'svn' ) ), array('k1' => 'v1', 'k2' => 'v2', ... , 'kn' => array( 'skn' => 'svn' ) ), );
need to turn into
k1; k2; ...; skn v1; v2; ...; svn v1; v2; ...; svn
If this is not clear, here is an illustration of what happens where:

Fortunately, this can be achieved using iterators:
$orderDetails = $array['OrderList_RetrieveByContactResult']['OrderDetails']; foreach( $orderDetails as $key => $details ) { $iterator = new RecursiveIteratorIterator( new RecursiveArrayIterator($details)); if($key === 0) { $keys = array(); foreach($iterator as $k => $v) { $keys[] = $k; } echo implode(';', $keys); } $values = array(); foreach($iterator as $val) { $values[] = $val; } echo PHP_EOL, implode(';', $values); }
The above code should output the described format. See http://www.ideone.com/I70dD for an example.
To write this to a file, you can collect it in a string variable and then file_put_contents all at once, or you use a pointer file and write it line by line. If you are not implode , but iterating over the $flattened , you can also use fputcsv .