When someone writes an entry in the textbox, I want to check the words that they used and find a match in a common word DB that I have. Each word in the DB had a number value that I need it to return.
I need to write an if statement that checks if a query returns a value, and if it does I need it to return -1.
This is what I have so far but right now but it only returns one word.
Entry::create($request->all());
// GETTING THE ARRY OF WORDS FROM entry_body( $entry_text)
$entry_text = $request->only('entry_body');
// REMOVE THE KEY AND JUST GET THE STRING VALUE
$entry_text = array_pull($entry_text,"entry_body");
$entry_noTag = strip_tags($entry_text);
// CONVERTE THE STRING ARRAY
$entry_explode = explode(" ", $entry_noTag);
// EACH WORD GETS ANALAYZED
$matched_words = Words::whereIn('word', $entry_explode)->get();
foreach ($entry_explode as $word) {
if ($matched_words == false){
return '-1';
}
else {
return $word;
}
};
I can get the code to return the matched values. What I need it to do is when a word in the array is not matched, it should return -1 so I know the word was not found in the DB.