savagenoob Posted February 20, 2012 Share Posted February 20, 2012 I am trying to break down an array to make it easier to read. An array that looks like Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0012844 1 [4] => 37 [5] => 1 etc...) I want to display it like: [0] => 0 [1] => 0 [2] => 0 etc... how can this be accomplished. Link to comment https://forums.phpfreaks.com/topic/257415-print-each-array-element-on-new-line/ Share on other sites More sharing options...
php.ajax.coder Posted February 20, 2012 Share Posted February 20, 2012 try <?php echo "<pre>"; print_r($array); echo "</pre>"; ?> or you could use the following <?php foreach($array as $key => $item){ echo "[" . $key . "] => " . $value . "<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/257415-print-each-array-element-on-new-line/#findComment-1319367 Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2012 Share Posted February 20, 2012 I assume you mean when using a print_r or var_dump statement? If so, use <pre> </pre> tags around the output to get the \n new-lines that are part of the output to cause new-lines to be displayed. Link to comment https://forums.phpfreaks.com/topic/257415-print-each-array-element-on-new-line/#findComment-1319369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.