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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:36:18+00:00 2026-05-25T10:36:18+00:00

Using CakePHP I’m getting multidimensional arrays and I can’t seem to figure out why

  • 0

Using CakePHP I’m getting multidimensional arrays and I can’t seem to figure out why sometimes I can access them via key and sometimes I can’t. For example I have an employee model with associated Plant information and find all correctly gets both sets of data and stores it in an array. The info is stored and accessed as $var['Emp'] and $var['Plant'] when I use Emp->find('all')

This gives a nice keyed array, like this:

$Employee = Array(
    [Plant] => Array(
            [0] => Array(
                 [ID]...

However for some employees (admins) they aren’t associated with lists of plants, so instead of using their accociated plant data, I need to give them a list of all plants period, so I use Plant->find('all'). The problem is the generated array is in a weird format as seen below:

$plants = Array(
    [0] => Array(
            [Plant] => Array(
                    [ID] =>...

So I can’t access $plants['Plant'], and I can’t use the top level array as my $Employee['Plant'] array. I know I could use a foreach and rewrite the $plants array to match the other format, but I have a whole site I’m converting to cake’s find('all') function so I would like to know why this difference is happening and how I can access the second array in a keyed fashion.

  • 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-25T10:36:18+00:00Added an answer on May 25, 2026 at 10:36 am

    In the first case, you are getting data back for an Employee and it groups associated models using the Model name.
    In the second case, you are getting back an array of all plants directly and that is just how CakePHP returns the objects. You need to iterate over the array to access each Plant object.

    I hope this makes sense.

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

Sidebar

Related Questions

After I uploaded my application created using cakephp, I found out that I had
I'm using cakePHP 1.2, and wondering how I can handle a URL that dynamically
using cakephp on email column in the db i have unique constraint, how can
I am using CakePHP and getting the following error Warning: Cache not configured properly.
I am using cakephp framework to build my application. I want that, whenever a
I am using CakePHP framework with MySQL database and I have problem in saving
I'm using CakePHP to build an application using the MVC Pattern, but my question
I'm using CakePHP but it's a question about the MVC pattern. I have in
I just started using CakePHP for a small project. I have rails experience, and
As part of a larger web-app (using CakePHP), I'm putting together a simple blog

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.