Page 1 of 1

trouble getting the modified array of a user function

Posted: Mon Apr 13, 2009 2:07 pm
by enoc22
I have a basic function i made to add to an array.

Code: Select all

 
The array--
[color=#FF0000]$num=array(1, 4, 7);[/color]
function add($i, $array){
    $array[]=$i;
    echo "<pre>";
    print_r($array);
    echo "</pre>";
}
[color=#FF0000]calling the function[/color]
add(20, $num);
The function will print_r out correctly. but i run into trouble when i try to get the new value outside of the function. I just get the original values, i've tried to return the array out of the function. but still nothing.
I'm sure i'm missing something here, but i'm not sure what?
Any Help would be Great.
Thanks
Oliver

Re: trouble getting the modified array of a user function

Posted: Mon Apr 13, 2009 2:13 pm
by n00b Saibot
You need to pass the array by reference... http://in.php.net/manual/en/language.re ... s.pass.php

Re: trouble getting the modified array of a user function

Posted: Mon Apr 13, 2009 3:08 pm
by enoc22
n00b Saibot AWSOME! that did the trick exatcly.

Thanks a million

Oliver