title: PHP JSON Encoding within foreach loop
body: <p>I'm trying to generate the following JSON data:</p>
  
  <pre><code>[
      {
          "ID": "A1000",
          "name": "John Simpson",
          "serialID": "S41234",
          "tagID": "ABC6456"
      },  
      {
          "ID": "B2000",
          "name": "Sally Smith",
          "serialID": "B5134536",
          "tagID": "KJJ451345"
      },
      {
          "ID": "A9854",
          "name": "Henry Jones",
          "serialID": "KY4239582309",
          "tagID": "HYG452435"
      }
  ]
  </code></pre>
  
  <p>from within a PHP <code>foreach</code> loop which looks like this:</p>
  
  <pre><code>foreach($records as $record) {
  
          $ID = $record-&gt;getField('propertyID');
          $name = $record-&gt;getField('assignedName');
          $serialID = $record-&gt;getField('serial');
          $tagID = $record-&gt;getField('tag');
  
      }
  </code></pre>
  
  <p>I've tried using:</p>
  
  <pre><code>$arr = array('ID' =&gt; $ID, 'name' =&gt; $name, 'serialID' =&gt; $serialID, 'tagID' =&gt; $tagID);
  </code></pre>
  
  <p>which works for each record within the loop, but can't work out the syntax to join them together into a single JSON data string?</p>