开发者

Is it possible to use heredoc inside an if statement?

开发者 https://www.devze.com 2022-12-11 22:05 出处:网络
Is it possible and is it the correct way to code using heredoc inside an if statementin php? if($selection!=\'\')

Is it possible and is it the correct way to code using heredoc inside an if statement in php?

if($selection!='')
{
    $price=getselection($selection,$getprice[$selection]);
    if ($selection<8)
    {
        print 'Please enter the  amount<br />';
        print '<form action="" method="post"><input type="text" name="money1" value="'.$money1.'">';
        print '<input type="text" name="money2" value="'.$money2.'">';
        print '<input type="text" name="money3" value="'.$money3.'"><input type="submit">';
        print '<input type="hidden" name="selection" value="'.$selection.'"';
        print '</form><br>';
            if (($money1!='')&&($money2!='')&&($money3!==''))
            {
                $total=$money1+$money2+$money3;
                $money=getmo开发者_Go百科ney($total);
                $change=getchange($total,$price);
            }
        }
    }
echo '</pre>';

I am trying to avoid getting out of the php code, and hopping into html and then back into php again, I was just trying to keep everything on the php script; in addition, using multiple print's is messy, thank you for not flaming.


Like this?

if (conditional)
{
  $foo = <<<html
    <tag></tag>
    <tag></tag>
    <tag></tag>
    <tag></tag>
    <tag></tag>
html;
}

I'm not aware of any situation where a heredoc 'will not work'. Just always take care to ensure that the closing statement of the heredoc has no leading characters. In my example html closes the heredoc and has absolutely no leading chars including spaces.


Yes, you can use heredocs inside if statements.

0

精彩评论

暂无评论...
验证码 换一张
取 消