Newbie PHP question

Status
Not open for further replies.

back4more

Seniorius Lurkius
20
1) Do the following two examples do the same thing?

//example 1
if (!$result)
{
echo("

Result is FALSE!

");
}
//example 2
if (!$result)
{
?>


Result is FALSE!


<?php
}

2) If they do the same thing, how should I decide which to use, when? In other words, when should I use echo, and when should I just pop out of php mode? I'm especially interested for large blocks of html in if's.

thanks!
b4m
 

irish

Ars Tribunus Militum
1,557
Subscriptor++
They will have the same result.

As to which method is better or not really depends on how much code you are going to be sending as output. In the example you gave, you are just echoing out a small block of code. For something like this example 1 will work like a charm.

In a situation where the if statement will determine whether or not a large form is shown, then example 2 would probably work better for you. I really think it really comes down to code readability.
 

back4more

Seniorius Lurkius
20
Thanks! You've confirmed my suspicions. The output I'll really be using is a large table that will grow as my database grows, so I'll probably pop out of php mode for it, but use echo's for the little stuff. I just couldn't get a read on how big a hunk of code I could or should put into an echo, and whenever possible I like to do the same thing the same way.

:)

b4m
 
Status
Not open for further replies.