- Joined
- Jun 21, 2010
- Messages
- 324
- Reaction score
- 54
Hello,
I've just recently discovered a blog that discusses how to implement PHP into your HTML programming and the result if you did it this way and that way and so on.
However, their was a topic discussed that involved techniques on how one may accomplish a task in HTML using PHP. The topic involved an array, and how one may print it into their HTML environment. The two results were vastly different.
Array:
Method 1: (which is now the way I prefer)
Method 2: (which is the method I dropped)
Method 1 implies that your HTML output is indented, however the source or from a developer's point of view is a little difficult to read.
Method 2 implies that your source code appears neater and more readable, however the output is messy and not indented.
My question to you, which do you prefer or would call the correct way of doing this task.
I've just recently discovered a blog that discusses how to implement PHP into your HTML programming and the result if you did it this way and that way and so on.
However, their was a topic discussed that involved techniques on how one may accomplish a task in HTML using PHP. The topic involved an array, and how one may print it into their HTML environment. The two results were vastly different.
Array:
PHP:
<?php
$names = array("John", "Jack", "Anna", "Ray", "Bob");
?>
Method 1: (which is now the way I prefer)
PHP:
<ul>
<?php foreach($names as $name) { ?>
<li><?php echo $name; ?></li>
<?php } ?>
</ul>
Method 2: (which is the method I dropped)
PHP:
<ul>
<?php
foreach($names as $name)
{
echo "<li>" . $name . "</li>";
}
?>
</ul>
Method 1 implies that your HTML output is indented, however the source or from a developer's point of view is a little difficult to read.
Method 2 implies that your source code appears neater and more readable, however the output is messy and not indented.
My question to you, which do you prefer or would call the correct way of doing this task.