Skip to content

Instantly share code, notes, and snippets.

@mahdiyazdani
Created November 1, 2020 22:47
Show Gist options
  • Save mahdiyazdani/1eff8cbe5a35575170558c5feecd1399 to your computer and use it in GitHub Desktop.
Save mahdiyazdani/1eff8cbe5a35575170558c5feecd1399 to your computer and use it in GitHub Desktop.
Explode a string into an array by delimiter
<?php
/**
* Explode a string into an array by $delimiter and remove empty values.
*
* @param string $string String to convert.
* @param string $delimiter Delimiter, defaults to ','.
* @return array
*/
function prefix_string_to_array( $string, $delimiter = ',' ) {
return is_array( $string ) ? $string : array_filter( explode( $delimiter, $string ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment