mohzameer
mohzameer

Reputation: 1179

PHP nested loop echos must not break into new line

Here is my code segment:

for($i=0;$i<23;$i++){
    echo "<div id=slotshead></div>";
    for($j=0;$j<30;$j++) {
        echo " <div id=slots></div>";
    }
    echo '<br>';
}

But, it doesn't work. I want the two echo statements inside the loop to be continued, not break into a new line. How can I fix it?

Upvotes: 0

Views: 750

Answers (2)

hjpotter92
hjpotter92

Reputation: 80649

If you just want to have each looped output display in a single line, you were nearly there.

Add the following to CSS; and you're done.

h3 > div {
    display: inline-block;
}

It'll generate the output as this fiddle.

Upvotes: 1

Aiias
Aiias

Reputation: 4748

If I understand what you're asking... this will combine your loops:

 for ($i = 0; $i < 23; $i++) {
   echo "<div id=slotshead></div>";
   for ($j = 0; $j < 30; $j++) {
     echo " <div id=slots></div>";
   }
 }
 echo '<br>';

Upvotes: 0

Related Questions