PHP: array passed by function reference?

I have this php function that should do some processing in a given array:

processArray($arrayToProcess) {

  $arrayToProcess['helloStackOverflow'] = TRUE;
}

The code then calls the following:

$niceArray = array('key' => 'value');
processArray($niceArray);

The key 'helloStackOverflow' is not available outside the processArray function. I tried to call the following:

processArray(&$niceArray);

Using "&" helps, however it does raise some warning:

Deprecated function: call forwarding by time is outdated; If you want to pass it by reference, change the declaration of populateForm_withTextfields ()

I tried there too, but it just stops the code.

How should I do it?

+3
source share
3 answers

You must define the link in the function, not in the function call.

function processArray(&$arrayToProcess) {
+12
source
processArray(&$arrayToProcess) {

  $arrayToProcess['helloStackOverflow'] = TRUE;
}

implements the link in PHP.

. http://fi2.php.net/references .

+8
processArray(&$arrayToProcess) {

  $arrayToProcess['helloStackOverflow'] = TRUE;
}

, .

http://php.net/manual/en/language.references.pass.php

.

+5

All Articles