PHP - How to modify multi-dimensional array item from within a function?
Posted
by
Marc
on Stack Overflow
See other posts from Stack Overflow
or by Marc
Published on 2012-04-14T17:17:27Z
Indexed on
2012/04/14
17:28 UTC
Read the original article
Hit count: 343
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';
}
© Stack Overflow or respective owner