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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:40:38+00:00 2026-06-04T05:40:38+00:00

I have an array and an external file, both contains lots of words. I

  • 0

I have an array and an external file, both contains lots of words. I want to match strings in the array with the entire external file. Then if there are identical words, I want to delete the word from the array.

Much shorten example:

 $words = {"apple", "orange", "banana", "grape", "peach"}

The external text file is a pure list of words

apple
banana
melon
...

I’d like to delete the words that are in the external file, and finally get this.

$words = {"orange", "grape", "peach"}

Should I call the external file, slice every line, then save them to another array? Then compare with the source array?
What is the most effective way to compare the array and a text file?
I’d appreciate your wisdom!

  • 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-04T05:40:40+00:00Added an answer on June 4, 2026 at 5:40 am

    You could use array_diff.(file to get an array from file.)

    $result = array_diff($words, file('path_to_file', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
    

    PS: If your external text file is very big, and you don’t want to load it to memory at one time, you could read it line by line, and check it whether it exists in the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem related to an array data which fetched from an external
I have array of strings, String[] data and it's 10 elements has value P
If I have an array that contains multiple FLV files like so: my @src_files
I have an external js file which I am creating a tag in. Problem
I have NSMutable array that holds data captured from external sensor through iphone. I
I have the below code to loop through and run an external file. I
I have this php script in an external file trying to get random question
I have an external JSON file (data.json) and would like to get data from
I have declared the following variable outside of an external js file because part
If I have this external XML file: <drivers> <folder> <name>Adobe</name> <driver> <name>acrobat distiller 3.0</name>

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.