How can unpack() be used to efficiently split a string into its individual components in PHP?

When dealing with a string that contains multiple components separated by a delimiter, unpack() can be used in PHP to efficiently split the string into its individual components. By specifying the format of the components in the unpack() function, PHP can extract and assign each component to a variable. This allows for a clean and concise way to process and work with the individual parts of the string.

$string = "John,Doe,30";
list($firstName, $lastName, $age) = unpack('A4firstName/A3lastName/Cage', $string);

echo $firstName; // Output: John
echo $lastName; // Output: Doe
echo $age; // Output: 30