title: PHP - Get object properties by variable
body: <p>I have an object with lots of properties. Some of the properties have their names start with the same string of text (in my example to come "bullet"), followed by an integer.</p>
  
  <p>I can fetch the property values as follows:</p>
  
  <pre><code>echo $objectName-&gt;bullet1;
  echo $objectName-&gt;bullet2;
  echo $objectName-&gt;bullet3;
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I'm trying to write a for loop to get the first 20 of these, and at the moment it looks a bit like:</p>
  
  <pre><code>for ($i = 1; $i &lt;= 20; $i++){
   if ($objectName-&gt;bullet$i){
    echo $objectName-&gt;bullet$i;
   }
  }
  </code></pre>
  
  <p>But this isn't working. I know I could write something like</p>
  
  <pre><code>$bulletsArray[1] = $objectName-&gt;bullet1;
  $bulletsArray[2] = $objectName-&gt;bullet2;
  $bulletsArray[3] = $objectName-&gt;bullet3;
  </code></pre>
  
  <p>all the way through to 20, then put a for loop on that, but I'm sure there must be a cleaner way. Can someone point me in the right direction?</p>