Removing a value from an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

Removing a value from an array

Post by hame22 »

Hi all

I have built my own search engine to search my site for resources.

It takes the search terms from the text box and then breaks the phrase into its individual words which I then search on and base relevancy upon.

Code: Select all

$q_array=explode(" ", $q);

	//count how many keywords there are
	$q_num=(integer)count($q_array);
	
	$r = query_table($q_num, $q_array, $cat);
the problem is it takes all words including common words such as "and", "a" etc.

what I would like to do is remove these type of words if they arise.

How would i go about removing these from the array before I pass it onto my listing function??

thanks in advance
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can setup an array of excluded words and then use array_diff() to create a new array from the collected words which excludes those excluded words.

Mac
Post Reply