使用函数时如何获取实际变量而不是副本

As the title sugests , i have a functions , i make a few changes to an array( this array is my paramether ). Then i realized that i used a copy of my actual array.

I know there was a way to get the actual array and not a copy , what was it ? Thank you all in advance , i know you will solve this in a jiffy :)

Here is where i use it

function findChildren($listOfParents)
    {
        static $depth=-1;
        $depth++;

        foreach ($listOfParents as $thisParent)
        {
            $thisParent->title = str_repeat(" >", $depth) . $thisParent->title;
            $children = page::model()->findAll(array('condition'=>'parent = ' . $thisParent->id));
            findChildren($children);
        }

        $depth--;
    }

So i need this $listOfParents, not his copy.

Try passing the value by reference

function findChildren(&$listOfParents)
    {
        static $depth=-1;
        $depth++;

        foreach ($listOfParents as $thisParent)
        {
            $thisParent->title = str_repeat(" >", $depth) . $thisParent->title;
            $children = page::model()->findAll(array('condition'=>'parent = ' . $thisParent->id));
            findChildren($children);
        }

        $depth--;
    }

Notice the ampersand &, which indicates you are working on the original variable, not a copy.

You're talking about passing a variable by reference: http://php.net/manual/en/language.references.pass.php

Try this:

function findChildren(&$listOfParents)
    {
        static $depth=-1;
        $depth++;

        foreach ($listOfParents as $thisParent)
        {
            $thisParent->title = str_repeat(" >", $depth) . $thisParent->title;
            $children = page::model()->findAll(array('condition'=>'parent = ' . $thisParent->id));
            findChildren($children);
        }

        $depth--;
    }

Pass it by reference.

function funcName (array &$param)
{
    // Do work here
}