Jump to content

How to format an echo statement to include a condition


floridaflatlander

Recommended Posts

I've been trying to format an echo statement to include a condition but I always have to split it into two or three echo  statements.

 

echo '</a>
</td>
<td class="info">
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';

 

Say I start with the above I'll then make it this

 

echo '</a>

</td>

<td class="info">';

if (this) {echo 'That';}

echo '<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';

 

How can I include a condition with out extra echo's? I've tried this with and with out brackets and parenthesis and of course it doesn't work.

 

echo '</a>

</td>

<td class="info">'.{if (this) {echo 'That';} }.'

<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';

 

Thanks

If you do all of the processing and parsing prior to writing any output to the screen, you'll find that things become a lot easier:

$extraInfo = '';

if (this) {
    $extraInfo = '<p>And some extra information</p>';
}

echo <<<Output
<p>This contains some information.</p>
$extraInfo
Output;

Thanks for the replys

 

This is in a loop and it works

 

$image = FALSE;
if ($board['id'] == 9) {$image = '9999999';}

echo '
</a>
</td>
<td class="info">'.$image.' '.'
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';

 

However when I take out the $image = FALSE; $image prints in all the loop's results. Why does it do that? Shouldn't $image be empty?

 

Anyway this works and I'll make a switch statement later

if ($board['id'] == 9) {$image = '9999999';} else {$image = FALSE;} and it works fine

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.