Skip to content

Instantly share code, notes, and snippets.

@webbower
Created July 15, 2015 21:27
Show Gist options
  • Save webbower/85ab0ea9c075fce9f54a to your computer and use it in GitHub Desktop.
Save webbower/85ab0ea9c075fce9f54a to your computer and use it in GitHub Desktop.
Generic array or object property getter
<?php
function getProp($data, $key) {
if (is_object($data)) {
return $data->$key;
} else if (is_array($data)) {
return $data[$key];
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment