Я пытаюсь проанализировать текст из текстового поля в форме, чтобы сгенерировать массив, который я можно перейти к методу find в cakePHP.
Я использовал регулярные выражения PHP для создания массива введенных терминов (включая «фразы, включенные в речевые знаки» как один элемент) )
Это может выглядеть вот так:
Код: Выделить всё
array(
(int) 0 => 'test',
(int) 1 => 'this out',
(int) 2 => 'now')
Код: Выделить всё
array(
array('ProjectDocumentSectionVariable.variable_description LIKE' => '%test%'),
array('ProjectDocumentSectionVariable.variable_description LIKE' => '%this out%'),
array('ProjectDocumentSectionVariable.variable_description LIKE' => '%now%'))
Обычно я получаю вот такую ужасную вещь:
Код: Выделить всё
array(
(int) 0 => array(
'ProjectDocumentSectionVariable.variable_description LIKE' => '%test%'
),
(int) 1 => array(
'ProjectDocumentSectionVariable.variable_description LIKE' => '%this out%'
),
(int) 2 => array(
'ProjectDocumentSectionVariable.variable_description LIKE' => '%now%'
))
Код: Выделить всё
$i = 0;
foreach($matches[1] as $match) :
$searcharray['ProjectDocumentSectionVariable.variable_description LIKE'] = "%" . $match . "%";
array_push($array_full,$searcharray);
$i++;
endforeach;
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/200 ... o-an-array
Мобильная версия