Categories
Mastering Development

Increment string from given array of letters or exclude specific letters from incremental with PHP

I have a list of allowed letters

$allowedLetters = array('B','C','D','F','G','H','J','K','L','M','N','P','R','S','T','V','W','X','Y','Z');

And from that array I would like to do string increment to get the following pattern:

BBB, BBC, BBD ... until ZZZ

I know that I can do string increment as simple as this:

$letters = array();
$letter = 'BBB';
while ($letter !== 'ZZZ') {    
    $letters[] = $letter++;    
}

print_r($letters);

But it will not match my allowed letters list, and I just can not find a way how to either do an increment using allowed list or just exclude letters that I do not want such as:

A,E,I,O,Q,U

What could be more simple? I would appreciate if anyone could assist.

Leave a Reply

Your email address will not be published. Required fields are marked *