First way
function enc($alphabet, $shift){
$array = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
$key = array_search($alphabet, $array);
$rkey = fmod($key+1+$shift, 26);
return $array[$rkey-1];
}
echo enc('a',0);
Second Way
function alpha($char,$num)
{
$i = 0;
foreach(range('A','Z') as $elements)
{
$alphabet[$i] = $elements;
$i++;
}
if(array_key_exists($num,$alphabet))
{
$char_index = array_search($char,$alphabet);
$index = $num + $char_index;
if($index >= 26)
{
$index = $index - 26;
$output = $alphabet[$index];
}
else
{
$output = $alphabet[$index];
}
}
else
{
$output = "out of range";
}
return $output;
}
echo alpha("Z",3);