Ok, so lets start with the code
<?php
function LuhnCalc($number) {
$chars = array_reverse(str_split($number, 1));
$odd = array_intersect_key($chars, array_fill_keys(range(1, count($chars), 2), null));
$even = array_intersect_key($chars, array_fill_keys(range(0, count($chars), 2), null));
$even = array_map(function($n) { return ($n >= 5)?2 * $n – 9:2 * $n; }, $even);
$total = array_sum($odd) + array_sum($even);
return ((floor($total / 10) + 1) * 10 – $total) % 10;
}
print LuhnCalc($_GET['num']);
?>
The errors are showing in the following lines
$even = array_map(function($n) { return ($n >= 5)?2 * $n – 9:2 * $n; }, $even);
return ((floor($total / 10) + 1) * 10 – $total) % 10;
The errors are
Parse error: syntax error, unexpected T_FUNCTION, expecting ‘)’ in
/home/MONKEY DO /public_html/gateway/crn.php on line 6
The error message says “I got a function but I expected a
)“. It’s telling you that according to the grammar of the parser, the tokenfunctionisn’t expected to happen at that point. When you writearray_map(function(...you are passing an anonymous function by using the tokenfunction, which the compiler doesn’t like.Anonymous functions were introduced in PHP 5.3. You’re probably running and older version of PHP. Check what version you’re running, and upgrade if you need to.