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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:09:50+00:00 2026-06-11T16:09:50+00:00

I have an object that needs to be returned, however I need to perform

  • 0

I have an object that needs to be returned, however I need to perform some pre-return manipulation before returning it.

The object has the following format:

object(PaginationHelper)[3]
    public 'current_page' => int 1
    public 'items_per_page' => int 10
    public 'dataset' => 
        array (size=10)
            0 => 
                object(AdvertSet)[4]
                    public 'Keywords' => string '' (length=0)
                    protected 'Adverts' => 
                        array (size=3) // SIZE = 3 SO REMOVE THIS FROM 'dataset' ARRAY
                        ...
                    public 'LiveStatus' => boolean false
            1 => 
                object(AdvertSet)[5]
                    public 'Keywords' => string '' (length=0)
                    protected 'Adverts' => 
                        array (size=1) // SIZE = 1 SO KEEP THIS IN 'dataset' ARRAY
                        ...
                    public 'LiveStatus' => boolean false

      etc etc ....
[End Object]

What I need to do:

Remove all parts of the ‘dataset’ array that doesn’t have an ‘Adverts’ count of 1, thereby preserving only those datasets that have an ‘Adverts’ array size of 1.
Retain the fact that it is an object, to be returned.

I’ve tried multi-dimensional recursive functions to get through this, however the fact that it’s an object and not an array is making progress hard, and I’m not sure I would be able to convert from an object to an array and back again without messing up the object’s internals.

Can anyone help with this? Here’s what I’ve gotten so far with a foreach…

foreach($results as $key => $value) {
    if($key == 'dataset') {
    // value is right array to check count
    foreach($value as $k => $v) {
        echo $v;
    }
}
}

It doesn’t work, but that’s the method I’m currently working on.

I’ve also tried something like:

if(count($results->dataset->(Array)AdvertSet->Adverts == 1) { }

but I can’t cast AdvertSet as Array.. Any help would be greatly appreciated!

Just a quick note: it doesn’t have to be removed from the array, I just eventually need the same object without those that have an Adverts count of 3. So this could involve copying to a new array without those that have an Adverts count of <> 1.

  • 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-11T16:09:51+00:00Added an answer on June 11, 2026 at 4:09 pm

    My first thought was:

    foreach($PaginationHelper->dataset as &$data) {
      if(count($data) !== 1)
         unset($data);
    }
    

    But after reading your question for the third time, I see you want to remove only those elements with a Adverts count not equal to 1.

    Looking at your structure, the Adverts array is protected, and therefore there is now way to access it without subclassing Advertset object.

    So, my final answer must be: It is not possible to remove them, with this structure!

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

Sidebar

Related Questions

When you have a domain object that needs to display as an interface control,
Let's say i have a griffon object that needs to be part of the
In an embedded program I have a screen object that needs to manage a
I have a current Date object that needs to be incremented by one day
Here is the scenario: I have an object called a Transaction that needs to
I have a list of object that need to be displayed and moveable on
I have a pretty large object that I need to pass to a function
I have a nested JSON object that I need to loop through, and the
If I have an object that holds the parameters for my method. I need
I have a simple Dictionary(of String, Object) that I need to iterate through and

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.