Monday, February 27, 2012

How to get an array with properties of an object in Php?

If you ever need to get an array of properties for an object in php this is the method that I created and might help you with that. The key is to use get_object_vars() method, parse each key and memorize in an array.
        
//Returns an array with properties of an object
 function GetAnArrayOfPropertiesForAnObject($Object)
 {
  $arrayProperties = get_object_vars( $Object);
  
  foreach($arrayProperties as $key=>$value)
  {
   $returnArray[] = strtolower($key);
  }
  return $returnArray;
 }

No comments:

Post a Comment