0

I've the following code:

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)

How can I combine the unit and message results in the elseif ($type == all) statement?

1
  • Until now it is still not clear what is the situation and what is the question. If you wanted to combine the description and title as strings then you where successful. (congratulations) Btw. when you ask questions try not to start your post with code and also have the code being the smallest part. Otherwise smart people will not even read what you wrote. Commented Apr 10, 2011 at 12:01

2 Answers 2

1

I'm not sure what you mean, is this what you want?

elseif ($type == 'all'){
    $item_title = $result["description"] . $result["title"];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that's exactly what I wanted. Thanks a lot :-)
0

You could create an associative array to store both....

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

You can then access them with $item_title['description'] and $item_title['title'].

If you need to determine if $item_title is an array or not, use is_array().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.