Hi to all. I am asking maybe a stupid question, but i would like to know if there is any defference between the writing code to the same php tag or in the same. Example:
<?php include ("dir/filename.php"); ?>
<?php echo "{$variable_from_the_included_file}"; ?>
OR THIS WAY:
<?php
include ("dir/filename.php");
echo "{$variable_from_the_included_file}";
?>
The same or separated php tag
Moderator: General Moderators
Re: The same or separated php tag
I find code easier to maintain when the logic is separated from the presentation, so most of my php code is in either a separate file or all wrapped up by the time I hit the <html> tag.
Because of this, once I hit the presentation, I'll usually do html as needed, even if it means having it on two lines:
(that is also an example of the one place where I miss the use of short tags, not being able to do <?= $abbr ?> LOL
As for something such as speed, I wrote a small block that had a few commands, one where they were all within the same PHP tags, one where each had their own.
I had it loop through and do them each 10,000 times, and to be honest, my extremely non-scientific method didn't come up with anything major as a difference that I could call one better than the other.
-Greg
Because of this, once I hit the presentation, I'll usually do html as needed, even if it means having it on two lines:
Code: Select all
<select name="optStates" id="optStates">
<?php foreach ($aryStates as $abbr->$state): ?>
<option value="<?php echo $abbr; ?>"><?php echo $state; ?></option>
<?php endforeach; ?>
</select>As for something such as speed, I wrote a small block that had a few commands, one where they were all within the same PHP tags, one where each had their own.
I had it loop through and do them each 10,000 times, and to be honest, my extremely non-scientific method didn't come up with anything major as a difference that I could call one better than the other.
-Greg