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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:52:21+00:00 2026-06-01T22:52:21+00:00

My problem is as follows. I have a multidimensional array. I declare my array.

  • 0

My problem is as follows. I have a multidimensional array. I declare my array. Then, I run some code that populates my array partially. Then i run a function, which among others is supposed to modify some item in my array from within the function. This is unfortunately not working. So my question is simple. Is it normal? And if yes, how can I overcome this. Thank you very much in advance for your replies. Cheers. Marc.

$list = array([0]=>
                   array(
                         [name]=>'James' 
                         [group]=>''
                         )
             ); 



my_function();
print_r($list); 

function my_function(){
     //some code here
     $list[0]['group'] = 'groupA';
}
  • 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-01T22:52:22+00:00Added an answer on June 1, 2026 at 10:52 pm

    you could pass the array to the function by reference

    my_function(&$list) {
    
        $list[0]['group'] = 'groupA';
    }
    
    $list = /*...*/
    my_function($list);
    

    or simply return the array from the function

    my_function($list) {
    
        $list[0]['group'] = 'groupA';
        return $list;
    }
    
    $list = /*...*/
    $list = my_function($list);
    

    or use a global

    my_function() {
    
        global $list;
        $list[0]['group'] = 'groupA';
    }
    
    $list = /*...*/
    my_function();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is as follows: I have an array of strings that contain dates
My problem is as follows. I have an array of objects in the form
A minimal code that reproduces the problem is as follows: <div class=cell> <input type=text
Greetings, I have a problem as follows: I have an SQL variable declared: DECLARE
The problem is as follows: I have an HttpHander, which works completely fine in
I have this particular problem which follows me since couple days. I used the
I have an optimization problem as follows. Given an array of positive integers, e.g.
Ok my problem is as follows; I have a class that describes a pet
I have run in to a slight problem. The story goes as follows: I
The problem is as follows: I have an environment with some variables defined like

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.