2013-06-10 3 views
0

루프를 작성하고 인수를 함수에 전달하는 데 도움이 필요합니다.루프의 PHP 대입 인수

switch ($action) { 
    case 'listItemTypeOne': 
    listItems(TypeOne); 
    break; 
    case 'newItemTypeOne': 
    newItem(TypeOne); 
    break; 
    case 'deleteItemTypeOne': 
    deleteItem(TypeOne); 
    break; 
    case 'listItemTypeTwo': 
    listItems(TypeTwo); 
    break; 
    case 'newItemTypeTwo': 
    newItem(TypeTwo); 
    break; 
    case 'deleteItemTypeOne': 
    deleteItem(TypeTwo); 
    break; 
    default: 
    listItems(TypeOne); 
} 

이러한 유형은 클래스를 나타냅니다.
지금 여기에 내가 아직

function listItem(Type) 
    $results = array(); 
    $data = TypeClass::getList(); 
    $results[Type] = $data['results']; 
} 

function newItem(Type) { 
    $results = array(); 
    $type = new TypeClass; 
    $type->storeFormValues($_POST); 
    $type->insert(); 
} 
function deleteItem(Type) { 
    $type->delete(); 
} 

내가 뭘 기능에 항목 유형을 전달하고 중복 기능을하지 않도록 할 필요가 이해할 수없는 부분이다? 어떤 종류의 루프?

답변

0
function listItems($Type){ 
    $results = array(); 
    swith($Type){ 
    case 'TypeOne': 
     $data = TypeOne::getList(); 
     break; 
    case 'TypeTwo': 
     $data = TypeTwo::getList(); 
     break; 
    } 
    $results[$Type] = $data['results']; 
} 
+0

저도 작동합니다! 감사 – DoughertySaw