Created
July 11, 2013 10:23
-
-
Save johnhunt/5974320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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