title: Getting object into array
body: <p>I'm not so advanced in PHP, just basic I can understand. I was trying an API and it returns it as object, how do I convert it to array? I did searched through stackoverflow and found lots of solution, but none works for me. <strong>$array returns empty array.</strong> Here is my code:-</p>
  
  <pre><code>while (1) {
  
      $line = '';
      $w-&gt;pollMessage();
      $msgs = $w-&gt;getMessages();
      foreach ($msgs as $m) {
  
          print_r($msgs);
          $array = json_decode(json_encode($msgs), true);
          print_r($array);
  }
  </code></pre>
  
  <p>And here is the result I get print_r($msgs):</p>
  
  <pre><code>Array
  (
      [0] =&gt; ProtocolNode Object
          (
              [tag:ProtocolNode:private] =&gt; message
              [attributeHash:ProtocolNode:private] =&gt; Array
                  (
                      [from] =&gt; amy
                      [type] =&gt; text
                      [id] =&gt; 3EB0E191F15B831D244E
                      [t] =&gt; 1462939886
                      [notify] =&gt; Nick
                  )
  
              [children:ProtocolNode:private] =&gt; Array
                  (
                      [0] =&gt; ProtocolNode Object
                          (
                              [tag:ProtocolNode:private] =&gt; enc
                              [attributeHash:ProtocolNode:private] =&gt; Array
                                  (
                                      [v] =&gt; 2
                                      [type] =&gt; msg
                                  )
  
                              [children:ProtocolNode:private] =&gt;
                              [data:ProtocolNode:private] =&gt; 3
  
                          )
  
                      [1] =&gt; ProtocolNode Object
                          (
                              [tag:ProtocolNode:private] =&gt; body
                              [attributeHash:ProtocolNode:private] =&gt;
                              [children:ProtocolNode:private] =&gt;
                              [data:ProtocolNode:private] =&gt; good
                          )
  
                  )
  
              [data:ProtocolNode:private] =&gt;
          )
  
  )
  </code></pre>