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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:26:40+00:00 2026-06-02T07:26:40+00:00

How would I alter the below code so that it returns itself as an

  • 0

How would I alter the below code so that it returns itself as an array. E.g using $this

    public function toArray($data) {

        if (is_array($data) || is_object($data)) {

            $result = array();

            foreach ($data as $key => $value){
                $result[$key] = $this->toArray($value);
            }

            return $result;
        }

        return $data;           
    }

So that instead of passing the $data it converts all the private properties from $this into an array.

  • 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-02T07:26:42+00:00Added an answer on June 2, 2026 at 7:26 am

    Something like this? get_object_vars()

    $data = get_object_vars ($this);
    

    also you can do like this(typecast):

    $data = (array)$this;
    

    Those two are a little different

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

Sidebar

Related Questions

using the script code below, this returns the images from facebook vertically. ive removed
How would I alter the below page and code so that when my 'news'
I currently have a function that takes a csv file, and returns an array
Hi was I hoping someone would help understand this behaviour of the below code.
I would like to make a view , and in that view alter the
UPDATE: I've edited the code below to show what I was using when I
I wrote the code below and I was expecting that, when the first loop
I have this learning code I wrote for the morris seq in f# that
I have a WCF service with many methods. I would like that after executing
Would be possibile to get the original data type after applying the ArrayToStringTransformer to

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.