deihler Posted December 20, 2018 Share Posted December 20, 2018 Hello, I am fairly new to PHP and I found some php code to print an array of numbers that create a combination - however, its slams all the numbers together without a space or a comma separator. How can I separate the numbers in this array with the given code? Ive attached a photo of the code. Quote Link to comment Share on other sites More sharing options...
benanamen Posted December 20, 2018 Share Posted December 20, 2018 Photo? Pictures are for hanging on the wall. Post your code using the code tags (<> on the menu) Quote Link to comment Share on other sites More sharing options...
Barand Posted December 20, 2018 Share Posted December 20, 2018 implode Quote Link to comment Share on other sites More sharing options...
requinix Posted December 20, 2018 Share Posted December 20, 2018 There's only one place in the code that produces output and it very clearly echoes a comma... Did you transcribe the code into a file? Did you copy it correctly? Quote Link to comment Share on other sites More sharing options...
dalecosp Posted December 20, 2018 Share Posted December 20, 2018 (edited) There are three echo() constructs that would produce output. A fourth such construct is commented out so it won't run. echo $data[$j]; echo ","; echo "<br>"; If you'd like a space after the comma, add a space after the comma in the 2nd echo shown above. If you're viewing this program's output in a browser, the "<br>" should produce a lineBReak. If you're not, it will just be so much garbledy-gook. Probably this line: //echo "n" Was actually mean to write a 'newline', like this: echo "\n"; Enabling (uncommenting) that line (with the change as shown) would produce a linebreak in console/non-browser output. The whole thing could be one-lined (including an additional space as I mentioned) thusly: echo $data[$j] . ", <br>\n"; Edited December 20, 2018 by dalecosp 1 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.