How can the PHP function list() be used as an alternative to explode() for assigning split parts to variables?

When we want to split a string into parts and assign those parts to variables, we can use the explode() function in PHP. However, an alternative approach is to use the list() function, which allows us to assign split parts directly to variables in a more concise way. This can be especially useful when we know the exact number of parts we are splitting the string into.

// Using list() as an alternative to explode() for assigning split parts to variables
$string = "apple,banana,orange";
list($fruit1, $fruit2, $fruit3) = explode(",", $string);

echo $fruit1; // Output: apple
echo $fruit2; // Output: banana
echo $fruit3; // Output: orange