Jump to content

Archived

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

dark dude

If statements in middle of text block

Recommended Posts

I'm having some problems with this:

[code]$DefBody = '[Some irrelevant code/]
<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr>
</table>
'.if($DefHaloMoonFig2=='0'){.' The Attacker has won the battle!'. } else {.'
The Defender has won the battle!
.}';[/code]

It doesnt seem to want the if statements there to work :(

Any help?


Thanks,
~Dark dude~

Share this post


Link to post
Share on other sites
such a messy piece of code...

[code]
$DefBody = '[Some irrelevant code/]<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr>
</table>';if($DefHaloMoonFig2=='0'){$DefBody.=' The Attacker has won the battle!'; } else {$DefBody.='
The Defender has won the battle!';}
[/code]

Share this post


Link to post
Share on other sites
Try this version:

[code]$DefBody = '[Some irrelevant code/]
<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr>
</table>'; // end of first part of definition

// now define the conditional adder and concatentate it
if($DefHaloMoonFig2=='0') {
    $DefBody.= ' The Attacker has won the battle!';
} else {
    $DefBody.= 'The Defender has won the battle!';
}
[/code]

Share this post


Link to post
Share on other sites
Use the [b]ternary[/b] operator within variable or flush type assignments!

[code]<?php

$a = 1;

echo 'the ' . ( $a == 1 ? 'sky' : 'water' ) . ' was blue';

?>[/code]

me!

Share this post


Link to post
Share on other sites

×

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.