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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:29:46+00:00 2026-06-03T11:29:46+00:00

I would like one of the attributes of my object to be an array

  • 0

I would like one of the attributes of my object to be an array of another type of object.

How do I represent this (i.e. public $someObjectArray;)

What would be the syntax to add an entry to this attribute?

What would be the syntax to reference the object?

To provide some (hopefully) useful context.

Lets assume that the object is property which has some attributes one of which is a number of tenants who will have their own properties like name, age etc…

  • 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-03T11:29:48+00:00Added an answer on June 3, 2026 at 11:29 am
    class Tenant {
        // properties, methods, etc
    }
    
    class Property {
        private $tenants = array();
    
        public function getTenants() {
            return $this->tenants;
        }
    
        public function addTenant(Tenant $tenant) {
            $this->tenants[] = $tenant;
        }
    }
    

    If the Tenant model has some sort of identifiable property (id, unique name, etc), you could factor that in to provide better accessor methods, eg

    class Tenant {
        private $id;
    
        public function getId() {
            return $this->id;
        }
    }
    
    class Property {
        private $tenants = array();
    
        public function getTenants() {
            return $this->tenants;
        }
    
        public function addTenant(Tenant $tenant) {
            $this->tenants[$tenant->getId()] = $tenant;
        }
    
        public function hasTenant($id) {
            return array_key_exists($id, $this->tenants);
        }
    
        public function getTenant($id) {
            if ($this->hasTenant($id)) {
                return $this->tenants[$id];
            }
            return null; // or throw an Exception
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this dilemma many times - and I would like one time and
I would like to have an AppWidget that designed like this one . Image:
I would like to append one DataTable to another DataTable. I see the DataTable
I would like to create one EMF object and use it in various Resource
I would like to base one component's x and y cooridnates according to another,
I have an single-dimensional array of PHP objects. Each object has two attributes, one
I would like to loop through a process and add an object to my
I would like to select an attribute based on its parent element. One way
I have a request in from a client that would like one of their
I would like to create a table that looks/behaves like the one to manage

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.