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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:43:58+00:00 2026-05-16T20:43:58+00:00

I want to be able to easily and quickly delete an array of needles

  • 0

I want to be able to easily and quickly delete an array of needles from a haystack array. In actual fact I have a comma separated list of numbers (though this is a string i know) that need to be deleted from a second comma separated list of number that I pull from a field in my sql database.

So I need –

$orig_needle_list = “3456,5678”;
The haystack list is in a field in a mysql database and is “3456, 4567, 5678, 6789” – so I basically want to update this field to “4567,6789”

Q1. Should I retrieve the haystack list, convert both to arrays and iterate over them with a nested foreach cycle and array_splice any matched values?

Q2 Can I use in_array to be faster than nested foreach method?

Q3 is there a way to cut out the middle man and update the field by performing this in an sql query?

thanks

  • 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-16T20:43:59+00:00Added an answer on May 16, 2026 at 8:43 pm

    you don’t need to iterate over things, there’s a function called array_diff:

    http://www.php.net/manual/en/function.array-diff.php

    So create 2 arrays of the comma separated list and use array_diff, the resulting array is the difference of these two.

    Storing comma separated lists in a database isn’t a good idea because it breaks normalization.

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

Sidebar

Related Questions

I am writing a little python app. I want to be able to easily
I've written a web user control which I want to be able to drop
Like many i have internationalized my app. On the simulator I am able to
I want to display a file content (HTML file) inside a web page using
For what reasons would I want to make my project an OSGI bundle as
OK, so we have a lot of sales data for each of our clients.
I'm contemplating using BDD for a personal project of mine. However, it is a
I am learning how to parse and generate JSON with the JSON gem. I
Feed burner changed their blog service return results that it returns blocks of javascript
I'm on a network with a couple of people that all listen to music

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.