Skip to content

Instantly share code, notes, and snippets.

@teomanofficial
Created November 10, 2019 08:37
Show Gist options
  • Save teomanofficial/ae1a8771f00617bc3c8860480793c62c to your computer and use it in GitHub Desktop.
Save teomanofficial/ae1a8771f00617bc3c8860480793c62c to your computer and use it in GitHub Desktop.
function pullOut(array &$arr, ...$parameters)
{
$result = [];
foreach ($parameters as $key => $parameter) {
$result[$key] = $arr[$parameter];
unset($arr[$parameter]);
}
return $result;
}
function array_values_recursive(array $arr): array
{
$arr = array_values($arr);
foreach ($arr as $key => $value) {
if (is_array($value)) {
$arr[$key] = array_values_recursive($value);
}
}
return $arr;
}
function array_list(array $array, &$total)
{
if (is_null($total)) {
$total = [];
}
foreach ($array as $item) {
if (is_array($item)) {
array_list($item, $total);
} else {
array_push($total, $item);
}
}
}
function scandir_filtered($dir)
{
if (!is_dir($dir)) {
throw new Exception("Directory Not Found");
}
return array_diff(scandir($dir), [".", ".."]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment