3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * Get luhn checksum * * @param $str_string * @param $int_base * @return string */ function get_luhn_checksum($str_string, $int_base) { $arr_chars = array_reverse(str_split($str_string)); $int_check_sum = 0; foreach ($arr_chars AS $int_index=>$str_char) { $int_adjustment = ((int)base_convert($str_char, $int_base, 10)) * ($int_index % 2 ? 1 : 2); $int_check_sum += $int_adjustment; echo "char $int_index is $str_char adjustment is +$int_adjustment running checksum is $int_check_sum\n"; } echo "Final checksum is $int_check_sum modded = " . ($int_check_sum % $int_base) . "\n"; return strtoupper(base_convert($int_base - ($int_check_sum % $int_base), 10, $int_base)); } echo get_luhn_checksum('7992739871', 10); exit; $str = get_luhn_checksum('0B022412500000009104', 16); echo $str;
based on TKO5D
Output for 5.0.0 - 7.2.0
char 0 is 1 adjustment is +2 running checksum is 2 char 1 is 7 adjustment is +7 running checksum is 9 char 2 is 8 adjustment is +16 running checksum is 25 char 3 is 9 adjustment is +9 running checksum is 34 char 4 is 3 adjustment is +6 running checksum is 40 char 5 is 7 adjustment is +7 running checksum is 47 char 6 is 2 adjustment is +4 running checksum is 51 char 7 is 9 adjustment is +9 running checksum is 60 char 8 is 9 adjustment is +18 running checksum is 78 char 9 is 7 adjustment is +7 running checksum is 85 Final checksum is 85 modded = 5 5
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_split() in /in/aqU8h on line 11
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: str_split() in /in/aqU8h on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_split() in /in/aqU8h on line 11