trouble getting the modified array of a user function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enoc22
Forum Commoner
Posts: 33
Joined: Wed Apr 01, 2009 12:45 pm

trouble getting the modified array of a user function

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Re: trouble getting the modified array of a user function

Post by n00b Saibot »

You need to pass the array by reference... http://in.php.net/manual/en/language.re ... s.pass.php
enoc22
Forum Commoner
Posts: 33
Joined: Wed Apr 01, 2009 12:45 pm

Re: trouble getting the modified array of a user function

Post by enoc22 »

n00b Saibot AWSOME! that did the trick exatcly.

Thanks a million

Oliver
Post Reply