stdClass Object to Array in PHP

If you deal with Restful services then many times you need to deal with stdClass Object. This generally create requirements to stdClass Object to Array conversion.

Here is the code to do that in Class:


<?php
	function objectToArray($o) {
		if (is_object($o)) {
			$o = get_object_vars($o);
		}
		if (is_array($o)) {
			return array_map(array($this,__METHOD__), $o);
		}
		else {
			return $o;
		}
	}
?>

For functional style of implementation, check here for this and related function - Function to Convert Multidimensional Arrays to stdClass Objects. It is nicely written.