<?php function decrement($str) { $index = strlen($str)-1; $ord = ord($str[$index]); if ($ord > 65) { // The final character is still greater than A, decrement return substr($str, 0, $index) . chr($ord-1); } if ($index > 0) { // Strip the final 2 characters and append a Z return substr($str, 0, $index-1) . 'Z'; } // Can't be decremented return false; } var_dump( decrement('A'), decrement('AA'), decrement('AAAA'), decrement('XXXZ') );
You have javascript disabled. You will not be able to edit any code.