How can the issue of generating an empty string in the array be prevented when using preg_split in PHP?

When using preg_split in PHP, the issue of generating an empty string in the array can be prevented by using the PREG_SPLIT_NO_EMPTY flag. This flag ensures that empty elements are not included in the resulting array.

$string = "Hello,World,,How,are,you";
$delimiter = ",";
$parts = preg_split("/$delimiter/", $string, -1, PREG_SPLIT_NO_EMPTY);
print_r($parts);