nick5449 Posted July 5, 2006 Share Posted July 5, 2006 I have an array that I want to display, but with a enter in between them. The code I have is this: [code] $x = 0; while($x != count($test)){ echo $test[$x]; echo "\n"; $x++; }[/code]The array is displayed but the enter isn't. Why wont '\n' work and how else can I get an enter to be displayed? Thanks. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 Web browsers do not display "\n" as a line break, you need to output the [code]<br>[/code] tag for that.Ken Quote Link to comment Share on other sites More sharing options...
Orio Posted July 5, 2006 Share Posted July 5, 2006 A suggestion for you nick, you can make your script shorter using "foreach":[code]<?phpforeach($test as $value){echo($val."<br>");}?>[/code][hr]Orio. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted July 5, 2006 Share Posted July 5, 2006 <br /> for break but you could do it like[code]<?phpwhile($x != count($test)) { echo $test[$x] ." <br /><br />"; $x++;}// orwhile ($x != count($test)) { echo "<p>{$test[$x]}</p>";}?>[/code] Quote Link to comment Share on other sites More sharing options...
nogray Posted July 5, 2006 Share Posted July 5, 2006 you can use [url=http://us2.php.net/manual/en/function.implode.php]implode()[/url] to do this[code]echo implode("<br />", $test);[/code] Quote Link to comment Share on other sites More sharing options...
nick5449 Posted July 5, 2006 Author Share Posted July 5, 2006 Awesome, that helps a lot. Thanks for the suggestions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.