Created
November 1, 2020 22:47
-
-
Save mahdiyazdani/1eff8cbe5a35575170558c5feecd1399 to your computer and use it in GitHub Desktop.
Explode a string into an array by delimiter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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