What is the purpose of grouping and splitting array contents in PHP?

Grouping and splitting array contents in PHP can be useful for organizing data or performing operations on subsets of the array. For example, you may want to group elements by a certain criteria or split an array into smaller chunks for processing. This can help make your code more efficient and easier to manage.

// Grouping array contents by a certain criteria
$fruits = array("apple", "banana", "orange", "kiwi", "grape");
$groupedFruits = array();
foreach ($fruits as $fruit) {
    $firstLetter = substr($fruit, 0, 1);
    $groupedFruits[$firstLetter][] = $fruit;
}
print_r($groupedFruits);

// Splitting array into smaller chunks
$numbers = range(1, 10);
$chunks = array_chunk($numbers, 3);
print_r($chunks);