What is the purpose of grouping arrays in PHP and what are the potential benefits?

Grouping arrays in PHP allows you to organize related data together, making it easier to manage and manipulate. By grouping arrays, you can access and work with related data more efficiently, improving code readability and maintainability. This can be particularly useful when dealing with large datasets or when you need to pass multiple related values to a function or method.

// Grouping arrays in PHP
$user1 = [
    'name' => 'John Doe',
    'email' => 'john.doe@example.com',
    'age' => 30
];

$user2 = [
    'name' => 'Jane Smith',
    'email' => 'jane.smith@example.com',
    'age' => 25
];

$users = [$user1, $user2];

// Accessing data from grouped arrays
echo $users[0]['name']; // Output: John Doe
echo $users[1]['email']; // Output: jane.smith@example.com