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

  • Home
  • SEARCH
  • 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 6021093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:39:45+00:00 2026-05-23T03:39:45+00:00

I’ve two arrays, the first ($needles) containing a bunch of Objects, the second ($stack)

  • 0

I’ve two arrays, the first ($needles) containing a bunch of Objects, the second ($stack) containing a bunch of key/values, but where one value is an array of Objects similar to the first array.

How can I delete all Objects within the target_p value in $stack where c_id matches any of the objects in $needle?

Thanks

Array ($needles)
(
    [0] => stdClass Object
        (
            [c_id] => 305164
            [neg] => 
            [seconds] => 604800
            [f_min] => 10
        )

    [1] => stdClass Object
        (
            [c_id] => 305165
            [neg] => 
            [seconds] => 604800
            [fr_min] => 10
        )

    [2] => stdClass Object
        (
            [c_id] => 305166
            [neg] => 
            [seconds] => 604800
            [f_min] => 10
        )

)
*****************
Array ($stack)
(
    [req_all] => 
    [target_p] => Array
        (
            [0] => stdClass Object
                (
                    [c_id] => 305164
                    [pid] => 2323554
                    [neg] => 
                    [seconds] => 
                    [f_min] => 
                )

            [1] => stdClass Object
                (
                    [c_id] => 305165
                    [pid] => 1964608
                    [neg] => 
                    [seconds] => 
                    [f_min] => 
                )

            [2] => stdClass Object
                (
                    [c_id] => 305166
                    [neg] => 1
                    [seconds] => 604800
                    [f_min] => 
                )

            [3] => stdClass Object
                (
                    [c_id] => 305167
                    [neg] => 1
                    [seconds] => 604800
                    [f_min] => 
                )

            [4] => stdClass Object
                (
                    [c_id] => 314022
                    [pid] => 4950148
                    [neg] => 
                    [seconds] => 
                    [f_min] => 
                )

        )

    [logical_e] => 
)

Desired output:

Array ($stack)
(
    [req_all] => 
    [target_p] => Array
        (
            [0] => stdClass Object
                (
                    [c_id] => 305167
                    [neg] => 1
                    [seconds] => 604800
                    [f_min] => 
                )

            [1] => stdClass Object
                (
                    [c_id] => 314022
                    [pid] => 4950148
                    [neg] => 
                    [seconds] => 
                    [f_min] => 
                )

        )

    [logical_e] => 
)
  • 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-23T03:39:46+00:00Added an answer on May 23, 2026 at 3:39 am

    Without rebuilding an array? Not really. But it’s still easy.

    Rebuild the needles array with keys matching the c_id values:

    $o_needles = array();
    foreach ($needles as $needle) {
        $o_needles[$needle->c_id] = $needle;
    }
    

    Then remove any nodes in the stack that has a c_id value matching a key in the modified needles array:

    foreach ($stack['target_p'] as $key => $obj) {
        if (array_key_exists($obj->c_id, $o_needles)) {
            unset($stack['target_p'][$key]);
        }
    }
    

    The performance/complexity is O(n + m).

    If you were to use a function like array_map, array_walk, array_filter or a nested foreach, you’d have to look over each of the needles for each element in the stack, which would be less efficient, especially with large datasets (O(n * m)).

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
I'm parsing an XML file, the creators of it stuck in a bunch social

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.