array in foreach within class
<p>I have a problem using an array within a foreach within a class. I get the warning..</p>

<blockquote>
  <p>PHP Warning:  Invalid argument supplied for foreach() </p>
</blockquote>

<p>on line</p>

<pre><code>foreach($this-&gt;recordOfDiscounts as $key =&gt; $discount)
</code></pre>

<p>The problematic function is below, </p>

<pre><code>public function modify_price( $price, $product_id ) {
    foreach($this-&gt;recordOfDiscounts as $key =&gt; $discount) {
        foreach($discount['get_one_free'] as $id) {
            if($id == $product_id){
                if( $discount['valid'] &gt; 0 ) {
                    $price -= $discount['cost'];
                    $this-&gt;recordOfDiscounts[$key]['valid'] -= 1;
                }
            }
        }
    }
    return $price;
}
</code></pre>

<p>I'm new to PHP, but what I've gathered is that the class scope (<code>$this-&gt;</code>) needs to prefix a var within a class. </p>

<pre><code>error_log(print_r($this-&gt;recordOfDiscounts),0);
</code></pre>

<p>outputs the correct array info, so I know its defined.</p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [valid] =&gt; 1
            [buy_one] =&gt; 2351
            [cost] =&gt; 20
            [old_cost] =&gt; 20
            [get_one_free] =&gt; Array
                (
                    [0] =&gt; 2471
                    [1] =&gt; 2470
                    [2] =&gt; 2472
                    [3] =&gt; 2473
                    [4] =&gt; 2474
                    [5] =&gt; 2475
                    [6] =&gt; 2476
                    [7] =&gt; 2477
                )

        )

)
</code></pre>
