I want explode
to return an empty array if the delimiter is not found.
Currently, I do something like this to get the explode
behavior I want:
if (strpos($line, ' ') === false) {
$entries = [];
} else {
$entries = explode(' ', $line);
}
There must be a more concise way of getting this behavior without having to use preg_split
. preg_split
has its own behavior that is also undesirable, such as including the delimiter in the resultant array entries.