Created
December 24, 2014 00:00
-
-
Save tikitikipoo/7403c78305b8f23bd01c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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