title: why does PHP json_encode ignore empty arrays?
body: <p>I have the following javascript that sends data to a PHP function:</p>
  
  <pre><code>&lt;script&gt;
      var mydata = {
                     id:123,
                     name: 'mike',
                     orders: []
      };
  
      $.ajax({
         type: 'POST',
         url:  'test.php',
         data: {save_data:mydata},
         success: function(data) {
                     alert('php received: ' + data);
         }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>and my <code>test.php</code> file contains the following code:</p>
  
  <pre><code>&lt;?php
       if (isset($_POST['save_data'])) {
            $json = json_encode($_POST['save_data']);
            echo $json;     // just to check what has been received
            exit();
       }
  ?&gt;
  </code></pre>
  
  <p>What I expect to received from PHP is:
  <code>{"id":"123","name":"mike","orders":"[]"}</code></p>
  
  <p>What I got back is <code>{"id":"123","name":"mike"}</code></p>
  
  <p>Notice that <code>orders</code> array has been eliminated from the output. No place holder for it. I tried adding some dummy elements in the array, and that worked fine, and I received the array back with the elements.</p>
  
  <p>I need PHP to receive the json object as is, even if it contains empty arrays.</p>
  
  <p>How can I do that?</p>