How can regular expressions, such as preg_split, be utilized in PHP to split strings based on multiple delimiters like commas and hyphens?

Regular expressions in PHP can be used to split strings based on multiple delimiters like commas and hyphens by using the preg_split function. By specifying a regular expression pattern that includes all the delimiters within square brackets, preg_split can split the string at any of the specified delimiters. This allows for more flexibility in splitting strings based on various characters.

$string = "apple,banana-cherry";
$delimiters = "/[,\\-]/"; // specify comma and hyphen as delimiters
$parts = preg_split($delimiters, $string);

print_r($parts);