Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created December 24, 2014 00:00
Show Gist options
  • Save tikitikipoo/7403c78305b8f23bd01c to your computer and use it in GitHub Desktop.
Save tikitikipoo/7403c78305b8f23bd01c to your computer and use it in GitHub Desktop.
public function extractByChangeKeyToUnderscore($data, $column = [], $json = true, $multiDArray = false) {
if (!$data) {
return null;
}
$result = [];
if ($multiDArray) {
foreach ($data as $i => $value) {
$result[$i] = $this->extractByChangeKeyToUnderscore($value, $json);
}
} else {
foreach ($data as $key => $value) {
if ($column) {
if (in_array($key, $column)) {
$result[Inflector::underscore($key)] = $value;
}
} else {
$result[Inflector::underscore($key)] = $value;
}
}
}
if ($json) {
$result = json_encode($result);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment