- array_map: documentation ( source)
- array_sum: documentation ( source)
- str_split: documentation ( source)
- ord: documentation ( source)
<?php
function power($s) {
return array_sum(array_map(function($e) {
return ord($e) - 64;
}, str_split($s)));
}
function battle($x, $y) {
$l = power($x);
$m = power($y);
return ($l > $m) ? $x : ($l == $m) ? "Tie!" : $y;
}
echo battle("FOUR", "FIVE");