PHP: simplify with algorithm?
- by tshabala
Hello.
Here's a piece of PHP code I think is not very "pretty", I'm sure it's possible to simplify it with for or something. I'm trying to find and algorithm that would work for this, but I can't figure it out, please help me.
Here's the code:
if(isset($four))
{
if(isset($navi[$one][$two][$three][$four])) echo "/content/" . $one . "/" . $two . "/" . $three . "/" .$four . ".php";
else echo "error";
}
else if(isset($three))
{
if(isset($navi[$one][$two][$three])) echo "/content/" . $one . "/" . $two . "/" . $three . ".php";
else echo "error";
}
else if(isset($two))
{
if(isset($navi[$one][$two])) echo "/content/" . $one . "/" . $two . ".php";
else echo "error";
}
else if(isset($one))
{
if(isset($navi[$one]))echo "/content/" . $one . ".php";
else echo "error";
}
else
{
echo "error";
}
Thanks!