How can you split an array into multiple parts based on specific elements in PHP?

To split an array into multiple parts based on specific elements in PHP, you can use the array_chunk() function. This function splits an array into chunks of a specified size. You can also use array_slice() to extract a slice of the array based on specific elements.

// Split an array into multiple parts based on specific elements
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Split the array into chunks of size 3
$chunks = array_chunk($array, 3);

print_r($chunks);

// Split the array based on specific elements
$slice = array_slice($array, 2, 5);

print_r($slice);