Jump to content

$data $array - the print result mashes all the numbers together


deihler

Recommended Posts

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.

 

 

 

 

array.jpg

Link to comment
Share on other sites

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 by dalecosp
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.