tags:

views:

48

answers:

2

I am calling this function which is modifying an array by reference:

function addWord(&$words, $wordIndex, $word)
{
 $words[$wordIndex] = $word;
}

At the function call,

addWord(&$words, $wordsIndex, $word);

($words is used only during the function call)

doesn't work. How do I make this or a similar functionality work? I want the addWord to be a separate function.

A: 

You don't need to pass an ampersand in the function call; only in the function declaration.

JW
Sorry.. I was trying out a bit.. Both didn't work actually. I get no error from php.
Salil
+1  A: 

call your function without the reference operator:

 $words = array();
 addWord($words, $wordsIndex, $word);
knittl
Yep.. This works.. I was busy solving a simple typo in addition to this. "$words = array();" is what i was missing.
Salil