0

I'm trying to do a complex find in CakePHP that has multiple NOT LIKE variables pulled from a table.

Just as an example of trying to use an array, something like:

$blocked_words = array();
array_push($blocked_words,'%apple%','%orange%','%strawberry%','%grapes%');

'NOT' => array(
array('Api.reason LIKE' => $blocked_words)),

does not work, only:

'NOT' => array(
array('Api.reason LIKE' => '%apple%'),
array('Api.reason LIKE' => '%orange%'),
array('Api.reason LIKE' => '%grapes%')),

seems to work. While this is great, it doesn't solve my need when i'm pulling an unknown number of variables. Is there a way to have LIKE work with an array or a workaround?

1 Answer 1

1

Do it:

$blocked_words = array('%apple%','%orange%','%strawberry%','%grapes%');
$conditions = array(); // conditions
foreach ($blocked_words as $word) {
   $conditions['NOT'][] = array('Api.reason LIKE' => "%$word%");
}
Sign up to request clarification or add additional context in comments.

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.