- str_split: documentation ( source)
- ord: documentation ( source)
<?php
function makePalindrome($word){
$result = 0;
$chars = str_split($word);
foreach($chars as $index => $char){
$ascii = ord($char);
if($index==$ascii-97){
$result+=$ascii-97;
}
}
return $result;
}
$test='abcde';
echo makePalindrome($test);