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 7787617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:43:43+00:00 2026-06-01T20:43:43+00:00

I have a PHP array of about 20,000 names, I need to filter through

  • 0

I have a PHP array of about 20,000 names, I need to filter through it and remove any name that has the word job, freelance, or project in the name.

Below is what I have started so far, it will cycle through the array and add the cleaned item to build a new clean array. I need help matching the “bad” words though. Please help if you can

$data1 = array('Phillyfreelance' , 'PhillyWebJobs', 'web2project', 'cleanname');

// freelance
// job
// project

$cleanArray = array();
foreach ($data1 as $name) {
    # if a term is matched, we remove it from our array
    if(preg_match('~\b(freelance|job|project)\b~i',$name)){
        echo 'word removed';

    }else{
        $cleanArray[] = $name;
    }

}

Right now it matches a word so if “freelance” is a name in the array it removes that item but if it is something like ImaFreelaner then it does not, I need to remove anything that has the matching words in it at all

  • 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-06-01T20:43:44+00:00Added an answer on June 1, 2026 at 8:43 pm

    A regular expression is not really necessary here — it’d likely be faster to use a few stripos calls. (Performance matters on this level because the search occurs for each of the 20,000 names.)

    With array_filter, which only keeps elements in the array for which the callback returns true:

    $data1 = array_filter($data1, function($el) {
            return stripos($el, 'job') === FALSE
                && stripos($el, 'freelance') === FALSE
                && stripos($el, 'project') === FALSE;
    });
    

    Here’s a more extensible / maintainable version, where the list of bad words can be loaded from an array rather than having to be explicitly denoted in the code:

    $data1 = array_filter($data1, function($el) {
            $bad_words = array('job', 'freelance', 'project');
            $word_okay = true;
    
            foreach ( $bad_words as $bad_word ) {
                if ( stripos($el, $bad_word) !== FALSE ) {
                    $word_okay = false;
                    break;
                }
            }
    
            return $word_okay;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php array that has a bunch of data that I need
PROBLEM I have a nested PHP array that I need to populate from flat
I have a PHP array that looks like this: Array{ [0] { 'id' =>
I have a PHP 2D array, many keys, each with one value, I need
i have php function that parses a xml url and gives me an array.this
I have a PHP array that I'd like to duplicate but only copy elements
I have about 5,000 pictures in a folder on my site. I need to
Background: I have a large 2D array of integers that I need to load
Trying to learn about php's arrays today. I have a set of arrays like
I have a PHP array with numbers of ID's in it. These numbers are

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.