title: Dynamically access an object property array element in PHP
body: <p>I have an object, that I would like to interact with dynamically. I would like to rename the game1_team1 in:</p>
  
  <pre><code>$default_value = $individual_match-&gt;field_match_game1_team1[0]['value'];
  </code></pre>
  
  <p>to be game1_team2, game2_team1, game2_team2, game3_team1, etc. Based on the loop they are in.</p>
  
  <p>I have tried:</p>
  
  <pre><code>$dynamic = 'field_match_game'.$i.'_team'.$j;
  $default_value = $individual_match-&gt;$dynamic[0]['value'];
  </code></pre>
  
  <p>but it returns </p>
  
  <blockquote>
    <p>Fatal error: Cannot use string offset
    as an array</p>
  </blockquote>
  
  <p>Update: Based on Saul's answer, I modified the code to:</p>
  
  <pre><code>$default_value = $individual_match-&gt;{'field_match_game'.$i.'_team'.$j}[0]['value'];
  </code></pre>
  
  <p>which got rid of the Fatal error, but doesn't return a value.</p>