开发者

Is this the right way to organize an equal statement?

Is this the right format? When i try to use it it gives me a blank page with no error msg.

$type = $row['page_type'];

$art = "Article";
$vid = "Video";
$pho = "Photo";
$link = "Link";

if ( $type === $art ) {
  $page = "art.php";
} elseIF ($type === $vid) {
  $page = "vid.php";
} elseIF ($type === $pho)开发者_运维知识库 {
  $page = "photo.php";
} else { 
  } elseIF ($type === $link) {
    $page = "link.php";
  } else { 
    echo("Error");
  }


You have an extra }else{

if ( $type === $art ) {
      $page = "art.php";
}elseif($type === $vid) {
      $page = "vid.php";
}elseif($type === $pho) {
      $page = "photo.php";
// This should not be here --> }else{ 
}elseif($type === $link) {
      $page = "link.php";
}else{ 
      echo("Error");
}

EDIT:

You could also use a hash for this:

$h = array("Article"=>"article.php", "Video"=>"vid.php", ...);
if(array_key_exists($type, $h)){
    $page = $h[$type];
}else{
    echo "Error";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜