2011-04-10 2 views
0

나는 다음과 같은 코드했습니다 :결합 PHP 변수

if ($type == 'unit'){ 
$item_title = $result["title"]; 
} 
elseif ($type == 'message'){ 
$item_title = $result["description"]; 
} 
    // all should combine unit and message 
elseif ($type == 'all'){ 
$item_title = $result["description"] 
    $item_title .= $result["title"]; 
} 

if (stripos($item_title, $filter) !== false || stripos($item_title, $filter) !== false) 

가 어떻게이 elseif ($type == all) 문에서 단위 및 메시지 결과를 결합 할 수 있습니까?

+0

지금까지는 상황이 무엇인지, 무엇이 문제인지 명확하지 않습니다. 설명과 제목을 문자열로 결합하고 싶다면 성공한 곳으로 이동하십시오. (축하) Btw. 질문을 할 때 코드로 게시물을 시작하지 말고 코드가 가장 작은 부분이되도록하십시오. 그렇지 않으면 똑똑한 사람들은 당신이 쓴 것을 읽지 못합니다. – erikbwork

답변

1

나는 당신이 원하는 것이 무엇인지 모르겠다. 당신은 모두를 저장하는 연관 배열을 만들 수

elseif ($type == 'all'){ 
    $item_title = $result["description"] . $result["title"]; 
} 
+0

그래, 그게 내가 원하는거야. 고마워 .-) – Dean

0

....

elseif ($type == 'all') { 
    $item_title = array(
        'description' => $result["description"], 
        'title' => $result["title"] 
       ); 
} 

그런 다음 $item_title['description']$item_title['title']에 액세스 할 수 있습니다.

$item_title이 배열인지 확인해야하는 경우 is_array()을 사용하십시오.