How can the concept of carrying over from Z to AA be implemented in PHP when generating a sequence of characters like the alphabet?

When generating a sequence of characters like the alphabet in PHP, the concept of carrying over from 'Z' to 'AA' can be implemented by using a loop to iterate through each character. When the current character reaches 'Z', it should reset to 'A' and the next character should be incremented. This process continues until the desired sequence length is reached.

$sequence = '';
$length = 5;

for ($i = 0; $i < $length; $i++) {
    $sequence .= chr(65 + ($i % 26)); // Convert ASCII value to character
}

echo $sequence;