|
Posted by Colin McKinnon on 01/20/06 23:24
chris_fieldhouse@hotmail.com wrote:
>
> I've ended up with this rather unsatisfying piece of code, it works,
> but it looks like a cludge.
>
I've seen worse.
> <code snippet>
> # now lets try searching for TO and CC emails! merge arrays,
> $emailSearch1= imap_search($conn, "TO test_address");
> $emailSearch2= imap_search($conn, "CC test_address");
>
> # attempt to merge arrays
> $emailSearch= array_merge ($emailSearch1, $emailSearch2);
>
> # if one array is 'empty', just assign the other array to be the search
> result
> if($emailSearch1 == false) $emailSearch=$emailSearch2;
> if($emailSearch2 == false) $emailSearch=$emailSearch1;
>
$results=array();
foreach(array('TO test_address','CC test address') as $iqry) {
if ($false !== ($sub = imap_search($conn, $iqry))) {
$results = array_merge($results, $sub);
}
}
....strikes me as more elegant - but less transparent. Also your code will
leave 'false' in the result when both queries fail, whereas my code returns
an empty array.
C.
[Back to original message]
|