How to Pass Class Variables in a Function Parameter
<p>The main function of the example class uses the reusableFunction twice with different data and attempts to send that data to a different instance variable ($this->result1container and $this->result2container) in each case, but the data doesn't get into the instance variables.</p>

<p>I could get it to work by making reusableFunction into two different functions, one with array_push($this->result1container, $resultdata) and the other with array_push($this->result2container, $resultdata), but I am trying to find a solution that doesn't require me to duplicate the code.</p>

<p>My solution was to try to pass the name of the result container into the function, but no go.  Does somebody know a way I could get this to work?</p>

<p>Example Code:</p>

<pre><code>Class Example {

    private $result1container = array();
    private $result2container = array();

    function __construct() {
        ;
    }

    function main($data1, $data2) {
        $this-&gt;reusableFunction($data1, $this-&gt;result1container);
        $this-&gt;reusableFunction($data2, $this-&gt;result2container);
    }

    function reusableFunction($data, $resultcontainer) {
        $resultdata = $data + 17;

        // PROBLEM HERE - $resultcontainer is apparently not equal to
        // $this-&gt;result1container or $this-&gt;result2container when I
        // try to pass them in through the parameter.

        array_push($resultcontainer, $resultdata);
    }

    function getResults() {
        return array(
            "Container 1" =&gt; $this-&gt;result1container, 
            "Container 2" =&gt; $this-&gt;result2container);
    }

}
</code></pre>

<p>(If this is a duplicate of a question, I apologize and will happily learn the answer from that question if somebody would be kind enough to point me there.  My research didn't turn up any answers, but this might just be because I didn't know the right question to be searching for)</p>
