PHP: simplify with algorithm?

Posted by tshabala on Stack Overflow See other posts from Stack Overflow or by tshabala
Published on 2010-06-15T10:11:41Z Indexed on 2010/06/15 10:22 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about php

Related posts about algorithm