Forum Moderators: coopster

Message Too Old, No Replies

array results output on online as opposed on separate lines

         

Flolondon

1:36 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



How do i get to echo details on oneline as opposed to the next line.

$car=array("red", "green", "white", "blue", "orange");
foreach $car as $color) {

echo "$color<BR/>";

I dont want the results on separate lines but on the same line with commons - please help

barns101

2:13 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



Simply exchange the <BR/> for a comma like so:


echo "$color,";

You'll have a comma at the end of the list but this could be removed if necessary with a little extra code.

Flolondon

2:21 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



<td>cars</td>\n";
echo " <td bgcolor=\"#00CCFF\">$car[0];,$car[1];,$car[2];,$car[3];,$car[4]</td>\n";
echo " </tr>\n";

thanks for the comma tip... but this is not ouputting the variable

barns101

2:57 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



Try removing the semi-colons:


<td>cars</td>\n";
echo " <td bgcolor=\"#00CCFF\">$car[0],$car[1],$car[2],$car[3],$car[4]</td>\n";
echo " </tr>\n";

Flolondon

3:02 pm on Mar 21, 2006 (gmt 0)

10+ Year Member



hello barnes

yes i tried removing the semi colons and still it did not work...please help

jatar_k

3:32 pm on Mar 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it is the array syntax inside the double quotes

<td>cars</td>\n";
echo " <td bgcolor=\"#00CCFF\">",$car[0],",",$car[1],",",$car[2],",",$car[3],",",$car[4],"</td>\n";
echo " </tr>\n";

you need to break out of the quoted part continuously or use braces around your vars