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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:03:56+00:00 2026-06-10T05:03:56+00:00

I have an object $obj that’s the result of json_encode, with a structure similar

  • 0

I have an object $obj that’s the result of json_encode, with a structure similar to this:

stdClass Object (
    [page] = 1
    [size] = -1
    [total] = 4
    [collection] = Array
        (
            [0] = stdClass Object
                (
                    [id] = 4e87de8e1a8840999f907fad
                    [description] = ffffffff
                    [code] = 82666
                    [status] = ACTIVE
                )

            [1] = stdClass Object
                (
                    [id] = 4e8b4b53fda5efeeec370e89
                    [description] = gggggggggg
                    [code] = 41874
                    [status] = ACTIVE
                )

            [2] = stdClass Object
                (
                    [id] = 4e8b4b5afda5efeeec370e8a
                    [description] = hhhhhhhhhhhhh
                    [code] = 15130
                    [status] = ACTIVE
                )

            [3] = stdClass Object
                (
                    [id] = 4e90a753e91a2713c95b56a0
                    [description] = jjjjjjjjjjjjjj
                    [code] = 323307
                    [status] = ACTIVE
                )

            [4] = stdClass Object
                (
                    [id] = 4e9e08da79597f0d3daba159
                    [description] = kkkkkkkkkkkkkk
                    [code] = 11310
                    [status] = ACTIVE
                )
        ) )

I have a value $code and want to search in $obj->collection, setting $id = to the id property of the object whose code property is equal to the value of $code. I’m doing this now with a conditional loop that checks the code property of each and sets $id if true, but I’m thinking there may be a command I’m missing out on due to being fairly unfamiliar with OO PHP.

Any way I could improve on this?

  • 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-10T05:03:57+00:00Added an answer on June 10, 2026 at 5:03 am

    Let me open with this: stdClass has no advantage over arrays (beside the fact it may “look cool”). It is in fact not OOP. To use arrays instead of stdClasses, have true as the second parameter to json_decode():

    json_decode($json_string, true);
    

    Will return an array.


    Other than that, iterating and checking for $code seems like the way to go. There’s no PHP function to do that for you (thank God). Arrays however have the distinct advantage of being able to be manipulated by array functions, (not to mention the efficiency boost).

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

Sidebar

Related Questions

I have an object obj that is passed into a helper method. public static
I have a byte[] that i obtained using Object ArrayList<Obj> Can anyone tell me
I have a couple functions like this: object obj.getChild(childIndex) int obj.numChildren() So I am
I have this interface: public interface IValidationCRUD { public ICRUDValidation IsValid(object obj); private void
i have a method as follows. test(Object obj){ } now within this method i
I have a 3d object wavefront .obj file, I want to use that .obj
I have some java code that gets and sets a session attribute: Object obj
I have a Linq-To-SQL object obj of type MyClass that I have loaded via
Imagine such situation that I have a function like this: Object f() { Object
I have something like this in my code <% while (i.hasNext()) { Object obj

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.