title: PHP Recursively Convert Object to Array
body: <p>I am trying to recursively convert a php object to an array. The function I wrote is this:</p>
  
  <pre><code>public function object_to_array($obj) {
      $array = (array) $obj;
      foreach ($array as $attribute) {
        if (is_array($attribute)) $attribute = $this-&gt;object_to_array($attribute);
        if (!is_string($attribute)) $attribute = (array) $attribute;
      }
      return $array;
  }
  </code></pre>
  
  <p>However, I still end up with objects in my outer array. Why is this? Is my function incorrect?</p>