2011-07-30 6 views
4

이 코드를 수정하기위한 제발 도와주세요, 내가 내부 스위치 경우에 넣어 원하는 :php -이 IF 조건을 스위치 안에 넣을 수 있습니까?

switch ($urlcomecatid) { 

if ($urlcomeparentid == 1 || $urlcomeparentid == 2 || $urlcomeparentid == 3) 
    break; 

case "50": 
case "51": 
case "52": 
case "109": 
case "110": 
    //do nothing and exit from switch 
    break; 
default: 
    header ("Location:http://www.example.com/tech/tech.php"); exit(); 
    break; 

}

답변

6

올바른 코드를해야 뭔가

switch ($urlcomecatid) { 
    case "50": 
    case "51": 
    case "52": 
    case "109": 
    case "110": 
     //do nothing and exit from switch 
     break; 
    default: 
     if ($urlcomeparentid == 1 || $urlcomeparentid == 2 || $urlcomeparentid == 3) 
      break; 
     header ("Location:http://www.example.com/tech/tech.php"); exit(); 
     break; 
} 
+0

도움 주셔서 감사합니다. – Kaveh

+0

0

사용 if 대신 switch 같은 .

<?php 
if(!in_array($urlcomeparentid, array(1, 2, 3) && !in_array($urlcomecatid, array('50', '51', '52', '109', '110')){ 
    header ("Location:http://www.example.com/tech/tech.php"); 
    exit(); 
} 

당신이 디버깅 할 때 문제의 잠재적 인 소스 스크립트의 나머지 부분을 죽이는과 같이 exit()을 피해야한다.

관련 문제