开发者

PHP get a boolean when it is set later in the page

In the header of my page I have 开发者_开发百科a conditional statement to check if $foo boolean is set, the trouble is that the $foo boolean doesn't get set until the footer is loaded. Any way to retroactively check the status of this boolean?


You can't "retroactively" check a condition. Your best bet may be to have the footer function execute first and save the footer in a variable, then echo it later.

Or, better, restructure the script so that all the state is determined first, then the HTML is created.


You can buffer the output of the footer, then generate the header and output it first.

ob_start();
outputFooter();
$footer= ob_get_clean();

outputHeader();
outputBody();
echo $footer;


No. At least not an easy way. You would have to use a templating system that can run the output after the page has finished loading.


Nope...Just a few alternatives, try refactoring the code to assure that value is being set first. Use session for setting the values may also be an option.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜