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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:01:16+00:00 2026-05-27T01:01:16+00:00

I am having a problem appending a few options to an array of modules.

  • 0

I am having a problem appending a few options to an array of modules. I am using Opencart and trying to extend a module by adding an image. To do this and ensure that the code will not break anything in the future I wanted to add to the array instead of replace it.

This is the code I have so far:

if (isset($this->request->post['special_module'])) {
    $modules = $this->request->post['special_module'];
} elseif ($this->config->get('special_module')) { 
    $modules = $this->config->get('special_module');
}

$this->load->model('tool/image');

foreach ($modules as $module) {
    if (isset($module['image']) && file_exists(DIR_IMAGE . $module['image'])) {
        $image = $module['image'];
    } else {
        $image = 'no_image.jpg';
    }           

    array_push($module, array(
        'image'        => $image,
        'thumb'        => $this->model_tool_image->resize($image, 100, 100)
    )); 
} 
print_r($modules);exit;
$this->data['modules'] = $modules;

Print Array, no image or thumb:

Array
(
    [0] => Array
        (
            [image_width] => 307
            [image_height] => 234
            [layout_id] => 1
            [position] => column_right
            [status] => 1
            [sort_order] => 1
        )

)

When I do array_push do I need to assign this back to the array?

  • 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-27T01:01:17+00:00Added an answer on May 27, 2026 at 1:01 am

    $module is being overwritten by the foreach() loop every time it iterates. So your push is basically a null-op, becaus foreach will destroy the previous $module (that you pushed to) with the next $module value coming out of $modules. You’d need something more like this:

    foreach($modules as &$module) {
        ...
        $module['image'] = $image;
        $module['thumb'] = ...;
    }
    

    The & before $module in the foreach turns it into a reference, so any modifications to $module within the loop will modify the original element in $modules, rather than a copy which would get trashed on every iteration.

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

Sidebar

Related Questions

I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem selecting an element with an id like this <li =0f:Bactidol_Recorder.mp4>. I
I'm having problem restricting a query in mdx, using except function at where clause.
We're having a bizarre problem with Indy10 where two large strings (a few hundred
Hi I am having no problem writing to or appending to a file, the
I'm having a problem where my second image is appearing in the place where
Im having this problem only with IE8 it even works well on IE6!!... Im
Interesting problem I'm having with a ListView. It's using a standard ArrayAdapter, with a
I've been trying to find an answer to this question for a few hours
I'm having a problem playing back audio data after appending extra recording to it.

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.