3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for git.master, git.master_jit, rfc.property-hooks
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

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
84.05 ms | 402 KiB | 8 Q