Skip to content

Instantly share code, notes, and snippets.

@jaketoolson
Created October 31, 2012 06:43
Show Gist options
  • Save jaketoolson/3985492 to your computer and use it in GitHub Desktop.
Save jaketoolson/3985492 to your computer and use it in GitHub Desktop.
PHP Code Sample 2
// Jake Toolson
// PHP Code Sample
// This illustrates a library method which shows my use of comments/notes.
/**
* Loop through field arrays and retrieve only the 'settings' for each field.
* These are NOT the attributes but rather the array which holds more specifics such as rules, type, label etc.
*
* $omit_key is used to omit a specific key=>value pair from the return array.
*
* @param array $fields
* @param str $omit_key
* @return array $settings
*/
public function get_field_settings($fields = array(), $omit_key = null)
{
foreach ($fields as $k => $v)
{
// Does the key need to be ommitted ?
if ( array_key_exists($omit_key, $v['settings']))
{
// Omission found! Delete it!
// TODO: continue would also work - benchmark the difference in time / efficiency.
unset($v['settings'][$omit_key]);
}
$settings[$k] = $v['settings'];
}
return $settings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment