Viewed k times. I would like to print an array to a file. I would like the file to look exactly similar like how a code like this looks. Is there any one lines solution for this rather than regular for each look. Improve this question. Gordon k 69 69 gold badges silver badges bronze badges. Atif Atif Add a comment. Active Oldest Votes. Improve this answer. Gordon Gordon k 69 69 gold badges silver badges bronze badges.
Show 3 more comments. Felix Kling Felix Kling k gold badges silver badges bronze badges. Sarfraz Sarfraz k 70 70 gold badges silver badges bronze badges. Ahmad Ahmad 4, 8 8 gold badges 26 26 silver badges 39 39 bronze badges. I just wrote this function to output an array as text: Should output nicely formatted array.
This script was created for internal use. This is not fool proof and should be used with trusted data only. Would be near impossible to do that with serialized output Not the cleanest function but it gets the job done. Here is the code. Dieter Gribnitz Dieter Gribnitz 4, 2 2 gold badges 38 38 silver badges 36 36 bronze badges. The boolean value determines whether the array will be returned.
The default value is false. The second parameter is the content to be loaded in the file. For example, create an associative array. An associative array is the type of array where the keys are strings instead of numbers. Create the keys as name , age , and bike. It does not print the items on the webpage. Return Values No value is returned. To change the default, edit your xdebug.
It can also adapt to terminal output if you execute it from there. No need to wrap it in a pre tag to get it to work in browsers. But it's not quite exact if the dumped variable contains HTML code. Default is 9em, but if you're expecting a huge output you'll probably want a higher value. Be careful this outputs to stdout stream 1 instead of the proper stderr stream 2.
0コメント