Skip to content

Instantly share code, notes, and snippets.

@MikePearce
Created October 20, 2010 11:31
Show Gist options
  • Save MikePearce/636245 to your computer and use it in GitHub Desktop.
Save MikePearce/636245 to your computer and use it in GitHub Desktop.
Needed to loop through a multiarray and replace {id} with something inside a class. Lambda functions FTW
/**
* Loop through the meta fields looking for things to replace
* @param array $replace
*/
protected function _metaReplacements(array $replace)
{
$doReplace = function(&$item, $key) use ($replace) {
foreach($replace AS $needle => $replace) {
$item = preg_replace('/'. $needle .'/', $replace, $item);
}
};
array_walk_recursive($this->_restResponse['head'], $doReplace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment