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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:58:10+00:00 2026-06-11T08:58:10+00:00

I am constructing an array like this: $result = $this->db->get($this->_table); foreach ($result->result_array() as $row)

  • 0

I am constructing an array like this:

$result = $this->db->get($this->_table);
foreach ($result->result_array() as $row) 
{
    $list->$row['categories_id'] = array('total_amount' => $row['total_amount'], 'other_stuff' => 'stuff');
}

This gives me a fatal exception “Cannot access empty property”

<?foreach ($category_list as $index => $row) {?>
          <td><?=$row?></td>
          <td><?=$list->$index['total_amount']?></td>
   <?}?>

but this works

<?foreach ($category_list as $index => $row) {?>
          <td><?=$row?></td>
          <? $temp = $list->$index; ?>
          <td><?=$temp['total_amount']?></td>
   <?}?>

Is there a better way to get the “total amount” from this object?

Even better – how can I make it so the object performs like this

 echo $list->$index->total_amount
  • 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-11T08:58:11+00:00Added an answer on June 11, 2026 at 8:58 am

    Ah, i see the problem.

    The way you are using it now you’re trying to access the element ‘total_amount’ of array index, not the element total_amount` of the array $list->$index. And of course,as $index is only an array key and as such a string or int, it won’t work.

    What about this: <td><?=$list->{$index}['total_amount']?></td>

    About your last question (accessing values via $list->$index->total_amount): You could probably cast your array to an object with (object).

    $list->$row['categories_id'] = (object) array('total_amount' => $row['total_amount'], 'other_stuff' => 'stuff');

    ——- Original Answer ——-

    I don’t know your exact object, but try the following:

    $transaction_list->index['total_amount']

    Notice the missing $ in front of the index? That’s the actual way to access class member variables. When using $ you’re actually doing something else.

    http://www.php.net/manual/en/language.oop5.basic.php

    http://www.php.net/manual/en/language.variables.variable.php

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

Sidebar

Related Questions

Im constructing an array of objects like this: var postData = []; $.each(selectedFields, function
I have a snippet of code like this: var profileLinks = new Array(); for
So, lets say in my main activity, i have an array declared like this,
I am having trouble constructing a jqGrid TreeGrid using local data. This method works
I'm constructing a regex that is looking for dates. I would like to return
This is a follow up question from Problem with array assignment I now have
I have a problem when constructing a polygon. The error message says something like:
Array: ['Date Taken', 'Weight'], I have this Array and the way I am iterating
As an addendum to this question Java loop efficiency ("for" vs. "foreach") I have
I'm creating an $item array that I'd like to push to $_SESSION['cart'] . After

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.