What best practices should be followed when dividing array contents into separate tables in PHP?

When dividing array contents into separate tables in PHP, it is best practice to loop through the array and insert each element into the corresponding table. This can be achieved by checking a condition for each element and inserting it into the appropriate table based on that condition.

// Sample array containing data to be divided into separate tables
$data = [
    ['name' => 'John', 'age' => 25, 'gender' => 'male'],
    ['name' => 'Jane', 'age' => 30, 'gender' => 'female'],
    ['name' => 'Alex', 'age' => 22, 'gender' => 'male']
];

// Loop through the array and insert data into separate tables based on gender
foreach($data as $item) {
    if($item['gender'] == 'male') {
        // Insert data into male table
    } else {
        // Insert data into female table
    }
}