heffe6 Posted March 4, 2009 Share Posted March 4, 2009 Hello everyone, I'm new here, but this seems like a great forum. I have a quick question that I haven't able to find a definitive answer to. I'm trying to teach myself php, and I want to be able to write with best practices in mind. Is it generally a better idea to create HTML with your php code like this?: <?php for($x=0;$x<5;$x++){ echo "<td>Number:</td>"; echo "<td>" . $x . "</td>"; } ?> Or is it better to write the php around the html like this?: <?php for($x=0;$x<5;$x++){ ?> <td>Number:</td> <td><?php echo $x ?></td> <?php } ?> Thanks! Link to comment https://forums.phpfreaks.com/topic/147887-quick-question/ Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 It all depends on how large the "segments" are and how you feel easier coding. Personally I'd code it like this: <?php for ($x=0;$x<5;++$x) { echo '<td>Number:</td>'; echo '<td>'.$x.'</td>'; } ?> But that's mainly because my text editor highlights all my code in different colors much like it has here. Link to comment https://forums.phpfreaks.com/topic/147887-quick-question/#findComment-776177 Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 Here are other ways you can code it... <?php for ($x=0;$x<5;++$x) { ?> <td>Number:</td> <td><?=$x;?></td> <?php } ?> ?> <?php for ($x=0;$x<5;++$x) { echo '<td>Number:</td><td>'.$x.'</td>'; } ?> <?php for ($x=0;$x<5;++$x) { echo '<td>Number:</td> <td>'.$x.'</td>'; } ?> Link to comment https://forums.phpfreaks.com/topic/147887-quick-question/#findComment-776194 Share on other sites More sharing options...
heffe6 Posted March 4, 2009 Author Share Posted March 4, 2009 Makes sense - thanks! Link to comment https://forums.phpfreaks.com/topic/147887-quick-question/#findComment-776582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.