First, I would recommend using the identical operator in PHP to compare strings that would be !==
instead of just !=
or else use strcmp()
to do so.
Another thing to say is that the second assignment to the string value of the $function
variable is in trouble, you should not concatenate the string this way.
One more addition would be to use an if ternary operator to accomplish such a condition imposed by you, without the need to create a variable as well.
In this part you should use .
to delimit a string from another, or make the string as one.
$function = '<li>''<a href="Alt_Papel.php">'.Alterar papel - D.'</a>''</li>'; //isto é totalmente incorreto.
$function = '<li>'.'<a href="Alt_Papel.php">'.'Alterar papel - D'.'</a>'.'</li>'; //isto é correto, porém não necessário.
$function = '<li><a href="Alt_Papel.php">Alterar papel - D</a></li>'; //isto é ideal.
For example, as there is another incorrect part in your string as well.
Applying the recommendations I mentioned your code would look like this:
<nav id="menu">
<ul>
<li><a href="index.php">Minimo Nulo</a></li>
<li><a href="Fechamento.php">Divergência de campos </a></li>
<?php
echo ($nivel !== 'MM' || $nivel !== 'AAAA') ? '' : '<li><a href="Alt_Papel.php"> Alterar papel - D </a></li>';
?>
</ul>
</nav>