$newSearchTheseArr begins in the for loop before that. My intention is to start a new definition of $searchTheseArr[$i] but the small words sorted out. $searchTheseArr[$i]showed all the words and $newSearchTheseArr[$i] sorts out the small words. $j=0; //to sort out all words with length less than 4 like AND, OR, BUT... for ($i=0; $i < count($searchTheseArr); $i++){ if(strlen($searchTheseArr[$i]) > 4){ $newSearchTheseArr[$j] = $searchTheseArr[$i]; //j renumbers the words of length 4 and up $j++; } } //sql searches only length 4 and up $newSearchTheseArr = array( for ($j=0; $j < count($newSearchTheseArr); $j++){ $query.=" CASE WHEN text_data LIKE '%" .$newSearchTheseArr[$j]. "%' THEN 1 ELSE 0 END"; if($j!=count($newSearchTheseArr)-1){ $query.=" +"; }else{ //removes the OR from the last line and replaces with the following $query.= " > 3"; } } ); PHP:
$newSearchTheseArr = array_filter($searchTheseArr, 'small_word'); function small_word($word) { return strlen($word) > 4; } PHP: www.php.net/array_filter
Ok. How about taking this into consideration? $searchThese = "the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt"; $searchTheseArray = explode(' ', $searchThese); print_r($searchTheseArray); PHP:
Ok well. It seems that there was one phrase missing: print_r($newSearchTheseArray); PHP: At the end: $searchThese = "the who and but Moses flock Jethro father priest Midian flock backside desert mountain Horeb angel appeared flame midst looked behold burned consumed Moses aside great sight burnt"; $searchTheseArray = explode(' ', $searchThese); print_r($searchTheseArray); $newSearchTheseArray = array_filter($searchTheseArray, 'small_word'); function small_word($word) { return strlen($word) > 4; } print_r($newSearchTheseArray); PHP: But I want it renumbered so that I can pass it through a For-loop. This is what I get so far: