Skip to content

Instantly share code, notes, and snippets.

@visb
Created October 6, 2014 19:44
Show Gist options
  • Select an option

  • Save visb/a90d71bd71e5a3594870 to your computer and use it in GitHub Desktop.

Select an option

Save visb/a90d71bd71e5a3594870 to your computer and use it in GitHub Desktop.
<?php
public function fn(array $options)
{
$this->parametrize($options, [['w', 'width'], ['h', 'height'], 'x', 'y']);
}
public function parametrize($options, $validOptions)
{
foreach ($options as $key => $value) {
if (in_array($key, $validOptions)) {
continue;
}
foreach ($validOptions as $index => $possibility) {
if (is_array($possibility) && in_array($key, $possibility)) {
unset($options[$key]);
$key = reset($validOptions[$index]);
$options[$key] = $value;
break;
}
}
}
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment