Skip to content

Instantly share code, notes, and snippets.

@johnhunt
Created July 11, 2013 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhunt/5974320 to your computer and use it in GitHub Desktop.
Save johnhunt/5974320 to your computer and use it in GitHub Desktop.
<?php
/**
* Method to quickly set many properties at once from an array
*
* Checks to see if property exists on the class, if so sets it to the value
* defined in the array.
*
* @param array $data
*/
public function exchangeArray(Array $data){
foreach ($data as $property => $value) {
// Check to see if object has this property, if so try and set it
if (property_exists(self, $property)) {
$this->$property = $value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment