Skip to content

Instantly share code, notes, and snippets.

@pecuchet
Created August 3, 2020 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pecuchet/1aac006594d35d929dc9ff53223a2f8f to your computer and use it in GitHub Desktop.
Save pecuchet/1aac006594d35d929dc9ff53223a2f8f to your computer and use it in GitHub Desktop.
Split a comma separated string into an array.
<?php
if (!function_exists('array_commas')) {
/**
* Split a comma separated string into an array.
* @param string $str
* @return array
*/
function array_commas(string $str): array
{
$str = explode(',', $str);
$str = array_map('trim', $str);
return array_filter($str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment