Skip to content

Commit

Permalink
Add Arr::copy() and copyValues()
Browse files Browse the repository at this point in the history
  • Loading branch information
paranoiq committed Apr 29, 2020
1 parent 97a687e commit 5184d15
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/common/lists/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,36 @@ public static function doForEach(array $array, callable $function): void
}
}

/**
* Copy array to remove any existing references
* @param mixed[] $array
* @return mixed[]
*/
public static function copy(array $array): array
{
$result = [];
foreach ($array as $key => $value) {
$result[$key] = $value;
}

return $result;
}

/**
* Copy array to remove any existing references. Drop keys
* @param mixed[] $array
* @return mixed[]
*/
public static function copyValues(array $array): array
{
$result = [];
foreach ($array as $value) {
$result[] = $value;
}

return $result;
}

// queries ---------------------------------------------------------------------------------------------------------

/**
Expand Down

0 comments on commit 5184d15

Please sign in to comment.