php - checking previous with dynamic variable names
<p>Looping through a dynamically-named array and comparing results to the previous positions results.</p>

<pre><code>if($s&gt;1 &amp;&amp; $s&lt;=10)
        {
            if( ${"strat{$s}"}[total] &gt; ${"strat{$s-1}"}[total] )
                $sl_best = $sl_mult; //if this one did better than the previous one, then grab the value
        } 
</code></pre>

<p>And I'm getting error messages related the the <code>${"strat{$s-1}"}[total]</code>, specifically the <code>{$s-1}</code> portion. Here is the error message:</p>

<pre><code>Parse error: syntax error, unexpected '-', expecting '}' ...
</code></pre>

<p>Any thoughts on how to check the previous array position on a dynamically named variable?</p>

<p>One solution I had was with <code>$previous = $s-1;</code> preceding every check and then substituting <code>$strat[$previous]</code> for <code>${"strat{$s-1}"}</code>, but this seems ugly and I wanted to see if anyone had a better solution?</p>
