Skip to content

Instantly share code, notes, and snippets.

@BackEndTea
Last active March 13, 2021 18:31
Show Gist options
  • Select an option

  • Save BackEndTea/c1da0db8f447f79567bd2894f469af04 to your computer and use it in GitHub Desktop.

Select an option

Save BackEndTea/c1da0db8f447f79567bd2894f469af04 to your computer and use it in GitHub Desktop.
array of strings to int
<?php
/**
* @param array<string> $in
*
* @return array<int>
*/
function withIntval(array $in): array
{
return array_map('intval', $in);
}
/**
* @param array<string> $in
*
* @return array<int>
*/
function withCast(array $in): array
{
return array_map(fn(string $val): int => (int) $val, $in);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment