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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:21:57+00:00 2026-05-13T18:21:57+00:00

I feel bad about mixing arrays with objects, but I’m not sure that I

  • 0

I feel bad about mixing arrays with objects, but I’m not sure that I should.

// Populate array
foreach($participants as $participant){
   $participants[$key]['contestant'] = new Contestant($participant);
   $participants[$key]['brand'] = new Brand($brand);
   $key++;
}

[...]

// Print array
foreach($participants as $participant){
   print "Name: " . $participant['contestant']->name;
   print "Nationality: " . $participant['contestant']->nationality;
}

I’m not comfortable about the $contestant['contestant']->name part. I’d feel better about using objects exclusively.

Is it in fact considered bad practice to mix objects and arrays, or am I obsessing over something that everyone else thinks is fine?

  • 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-13T18:21:58+00:00Added an answer on May 13, 2026 at 6:21 pm

    It feels fine to me. Where an array makes sense, use an array. Where an object makes sense, use an object.

    However, maybe you feel that a participant makes more sense as an object, which, looking at this relatively small code sample, it just may. If so, write up a quick Participant class. If that feels like too much overhead, then don’t worry about it. At this point, it’s personal preference, since your code, does, in fact, work. It’s all about which codebase you would prefer to be working with in the future.

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

Sidebar

Related Questions

I feel bad about not getting this. But, although I have read several articles
Should I feel bad about leaving out the -khtml- prefix from css attributes like
I feel bad about asking a question so simple, but I can't figure this
I feel bad for asking this, but I can't find any answer on the
I know that storing such a sensitive data is a bad idea. But if
I have a very bad feeling about using lock in my code but now
I've been using JSLint to make me feel bad about my JavaScript. It is
I feel bad because it is very likely this has already been answered and
Feel free to close and/or redirect if this has been asked, but here's my
I feel like I am not writing this correctly and this is my first

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.