Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7621277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:09:27+00:00 2026-05-31T04:09:27+00:00

I have a filter function which is supposed to check two fields in an

  • 0

I have a filter function which is supposed to check two “fields” in an array, these are cold name and description.

I also have words stored in a database which the filter function should accept certain words (true) and decline certain words (false).

Example:
Every post coming in containing the word car should be accepted.

In the database I have stored following words which is accepted:
car (obviously)

Not accepted:
truck
traktor
buss

So I have a function that is supposed to go through the two fields (name and description) in the array match them to the words stored in the database and look if the fields contains the accepted word or any of the not accepted words.

My function looks like this
$arr = incoming array with the fields name and description.
$a[‘value’] = If it is 0 the word is not accepted if it is 1 the word are accepted.
$a[‘filter’] = The word from the database.

function checkFilter($arr)
{
    $name = strtolower($arr['name']);
    $description = strtolower($arr['description']);

    $dbh = $this->connect();    
    $rs = $dbh->prepare("SELECT * FROM filter");
    $rs->execute();
    $all = $rs->fetchAll();

foreach($all as $a)
{
    if($a['value'] == 0 && strstr($name, strtolower($a['filter']), true))
    {
        return false;
        break;
    }

    if($a['value'] == 0 && strstr($description, strtolower($a['filter']), true))
    {
        return false;
        break;
    }

    if($a['value'] == 1 && strstr($name, strtolower($a['filter']), true))
    {
        return true;
        break;
    }

    if($a['value'] == 1 && strstr($description, strtolower($a['filter']), true))
    {
        return true;
        break;
    }
}
return false;       
}

As you se my thought here is, if any of the not acceptable words are showing up I want to return false from the function and break. This because it doesn’t matter if the accepted word is in the name or description if the not accepted word is already there.

After the foreach I have a return false because if it can’t find the accepted word (eg car) it should be filtred out.

My problem is that this doesn’t seems to work. It doesn’t seems to break the function after it hase come into an if statement.

How should I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:09:28+00:00Added an answer on May 31, 2026 at 4:09 am

    Try this:

    function checkFilter($arr)
    {
    $good=false;
    $bad=false;
    
        $name = strtolower($arr['name']);
        $description = strtolower($arr['description']);
    
        $dbh = $this->connect();    
        $rs = $dbh->prepare("SELECT * FROM filter");
        $rs->execute();
        $all = $rs->fetchAll();
    
    foreach ($all as $a)
      {
        if($a['value']==0)
          {
            if(strpos($name,$a['filter']!=='false') || strpos($description,$a['filter']!=='false') ){$good=true;}
          }
        if($a['value']==1)
          {
            if(strpos($name,$a['filter']!=='false') || strpos($description,$a['filter']!=='false') ){$bad=true;}
          }    
      }
    
    return ($good && !$bad);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a filter which is supposed to work on arbitrary tensors. For my
Suppose I have a function (it really does what the name says): filter :
I have a javascript function which should filter a specific row from a shape
I have an Extension method which is supposed to filter a Queryable object (IQueryable)
I have a control that has a Filter property that expects a function that
I have to filter a text file filter.tmp containing two types of lines, this
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
I have a function which loads an image/text into my game.I'm using gluBuild2DMipmaps() to
I have a view function which renders json. I am able to specify which
I have a function which signature is String -> String -> IO (Maybe String)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.