Array not working

Discussion in 'PHP' started by gilgalbiblewheel, Jul 30, 2008.

  1. #1
    $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:

     
    gilgalbiblewheel, Jul 30, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $newSearchTheseArr = array_filter($searchTheseArr, 'small_word');
    
    function small_word($word)
    {
        return strlen($word) > 4;
    }
    
    PHP:
    www.php.net/array_filter
     
    nico_swd, Jul 30, 2008 IP
  3. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    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:
     
    gilgalbiblewheel, Jul 30, 2008 IP
  4. gilgalbiblewheel

    gilgalbiblewheel Well-Known Member

    Messages:
    435
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #4
    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:
     
    gilgalbiblewheel, Jul 30, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    
    $newSearchTheseArray = array_values($newSearchTheseArray);
    
    PHP:
    ... this will re-index it.
     
    nico_swd, Jul 30, 2008 IP