I'd extract that algorithm in a function:
$string = $post['message'];
$data = array_map('strtolower', explode(' ', $string));
$tag = '-fr-';
function filterByTag($data, $tags) {
return array_intersect($data, $tags);
}
$filteredData = filterByTag($data, array('-fr'));
// AND
$filteredData = filterByTag($filteredData, array('#science'));
Calling it successively results in an AND
condition.
Calling it with multiple array values in the $tags
parameter would be an OR
.