What is the purpose of grouping arrays in PHP and how can it be achieved effectively?

Grouping arrays in PHP can be useful when you want to organize related data together for easier access and manipulation. One effective way to achieve this is by using associative arrays, where each key represents a group or category, and the corresponding value is an array containing the related data. This allows you to easily access and work with the grouped data in a structured manner.

// Example of grouping arrays in PHP using associative arrays
$data = array(
    'group1' => array('item1', 'item2', 'item3'),
    'group2' => array('item4', 'item5'),
    'group3' => array('item6', 'item7', 'item8')
);

// Accessing data from a specific group
echo "Items in group1: " . implode(', ', $data['group1']);