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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:49:15+00:00 2026-05-27T18:49:15+00:00

I was working OpenCart and added such code to Controller to show all the

  • 0

I was working OpenCart and added such code to Controller to show all the manufacturers to User:

  $this->load->model("catalog/manufacturer");
  $manufacturers = $this->model_catalog_manufacturer->getManufacturers();
  $allbrands = array();
  foreach ($manufacturers as $brand)
  {
    $brand["url"] = $this->url->link("product/manufacturer/product&manufacturer_id=".(string) $brand["manufacturer_id"],"","SSL");
    $allbrands[] = $brand;
  }

  $this->data["manufacturers"] = $allbrands;

It worked just fine but my previous code didn’t work which is below:

  $this->load->model("catalog/manufacturer");
  $manufacturers = $this->model_catalog_manufacturer->getManufacturers();
  $allbrands = array();
  foreach ($manufacturers as $brand)
  {
    $brand["url"] = $this->url->link("product/manufacturer/product&manufacturer_id=".(string) $brand["manufacturer_id"],"","SSL");
  }

  $this->data["manufacturers"] = $manufactures;

What I was thinking is arrays are objects so they are pointed at references so if I change $brand variable then $manufacturers will also have arrays that have "url" as index but didn’t work and PHP complains that it doesn’t have any "url" index.

Assigning a new index to an array cause it to be recreated with new object in the heap or it extends the current object’s place in the heap?

Any ideas, what might it happen?

  • 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-27T18:49:16+00:00Added an answer on May 27, 2026 at 6:49 pm

    foreach [docs] is creating copies of the array values:

    In order to be able to directly modify array elements within the loop precede $value with &. In that case the value will be assigned by reference.

    and

    Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().

    This should work:

    foreach ($manufacturers as &$brand) {
        $brand["url"] = $this->url->link("product/manufacturer/product&manufacturer_id=".(string) $brand["manufacturer_id"],"","SSL");
    }
    unset($brand);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with Json, how can I NSlog only the title in this code: NSDictionary
Working Example: This is almost identical to code I use in another places on
Working in an app where a page_title method was defined in application_helper.rb as such:
Working demo CLick $(document).ready(function(e) { $('span#pijlr, span#pijll').show(); $('#gallery').css('overflow','hidden'); $('span#pijlr').click(function(e) { if (!$('#gallcont').is(':animated')) { var
I am working on Opencart 1.5.1.3. After logging in I am automatically taken to
I am working on a project with opencart 1.5.1.3 On the checkout page, it
Im using Open Cart version 1.4.9.2. I was host this and working more than
Working with MVC 2 ad with the help of some friends I thought all
Working SQL The following code works as expected, returning two columns of data (a
Working with COM interop, I can call a managed function from within unmanaged code.

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.