Skip to content

Instantly share code, notes, and snippets.

@felipevolpatto
Created November 19, 2013 19:11
Show Gist options
  • Save felipevolpatto/7550771 to your computer and use it in GitHub Desktop.
Save felipevolpatto/7550771 to your computer and use it in GitHub Desktop.
PHP Object Helper. toArray() -> Object to array implementation.
<?php
class ObjectHelper {
private function __construct() { }
public static function toArray($obj) {
if (is_object($obj)) {
$obj = get_object_vars($obj);
}
return (is_array($obj))
? array_map(array(__CLASS__, __FUNCTION__), $obj)
: $obj;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment