mardi 6 novembre 2018

Nest php if/else statement in variable

I want to put an if/else statement in an include but it doesn't work out. The result is the statement published as plain text.

See this page.

Basis file sample.php

<?php include "include.php";?>
<?php $name = "Menu 1";?>
<html>
<body>      
<?php echo $showMenu ;?>    
</body>
</html>

Include file include.php

<?php
$showMenu='if($name=="Menu 1")
{echo "Menu 1";}
else
{echo "Menu 2";}';
?>

If I'm right the problem is situated in the include.php file, but don't know how to adjust the if/else statement in the include to make it work. If you put the if/else statement inline in the sample.php file it works though. Tnx all for helping out!

Aucun commentaire:

Enregistrer un commentaire