0

This is part of a bigger code, I keep getting the parse error ::: if I create the if function outside of the $return & reference it with a session it works but this is not "good" coding :::how can I resolve this nagging issue or better construct my return value? ::: Any help greatly appreciated :::

$return = '';
    $return .='<div id="viewport">'. "\n";
    $return .= $ic . "\n";
    $return .='<div id="' . $wallID . '"></div>'. "\n"; 
    $return .='</div>'. "\n";                                  
    $return .= if( isset($coda) )'<div id="coda' . $wallID . '"></div>';. "\n";
    $return .='</div>'. "\n";                                   
    $return .='<div class="clearfix"></div>'. "\n";

 return $return;
2
  • Which line is the error in? Please always specify the line of the error message Commented Nov 6, 2011 at 13:39
  • Ah, I see now. You can't use if like that - put it before the $return.= assignment Commented Nov 6, 2011 at 13:40

3 Answers 3

3

Just use a proper if:

...
if( isset($coda) ) {
  $return .= '<div id="coda' . $wallID . '"></div>'. "\n";
}
$return .= ...
...
Sign up to request clarification or add additional context in comments.

Comments

1

This one is probably problematic

$return .= if( isset($coda) )'<div id="coda' . $wallID . '"></div>';. "\n";

it should be

$return .= ((isset($coda)) ? '<div id="coda' . $wallID . '"></div>' : '')."\n";

To make it all more clean, I'd suggest you to use HEREDOC

1 Comment

THX for the heads up on HEREDOC ::: Read some documentation & implemented it in my code ... looks much cleaner
0

Use a ternary operator instead of the misused if block:

$return .= isset($coda) ? "<div id='coda{$wallID}'></div>\n" : '';

or a more readable if block as @Mat sugested

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.