How can duplicate keys be avoided when calculating array keys based on data in PHP?

To avoid duplicate keys when calculating array keys based on data in PHP, you can use a hashing function like `md5()` or `sha1()` to generate unique keys from the data. This ensures that each key is unique and prevents any duplicates from occurring.

$data = ["apple", "banana", "cherry", "apple", "banana"];
$uniqueKeys = [];

foreach ($data as $item) {
    $key = md5($item);
    $uniqueKeys[$key] = $item;
}

print_r($uniqueKeys);