pastebin - collaborative debugging tool
kpaste.net RSS

Difference between
modified post bcdc08178 by Anonymous on Sat 19th Feb 2011 21:27
original post d77 by Admin on Fri 11th Feb 2011 02:06
Download diff
Show old version | new version | both versions

    
11
<?php
22
function roundup ($number, $increments) {
33
        $increments = 1 / $increments;
44
        return (ceil($number * $increments) / $increments);
55
}
66
7-
$num = "49927398717";
7+
@@$num = "49927398717";
88
99
$double = false;
1010
$ret = "";
1111
1212
for ($i = strlen($num) - 1; $i >= 0; $i--) {
1313
        $ret .= ($double ? $num[$i] * 2 : $num[$i]);
1414
        $double = !$double;
1515
}
1616
$ret = strrev($ret);
1717
$sum = 0;
1818
1919
for ($i = 0; $i < strlen($ret); $i++) {
2020
        $sum += $ret[$i];
2121
}
2222
echo "\$ret = $ret\n";
2323
echo "\$sum = $sum\n";
2424
2525
if ($sum % 10) {
2626
        $check_digit = roundup($sum, 10) - $sum;
2727
        echo "Invalid - (Valid with check digit $check_digit)\n";
2828
} else {
2929
        echo "Valid\n";
3030
}
3131
?>
3232

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at