Created
January 5, 2016 13:25
-
-
Save coquer/7c28b9f7b49029cef46d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function validate_cpr_number( $cpr ) { | |
if ( empty( $cpr ) ) { | |
return false; | |
} | |
$cpr = str_split( $cpr ); | |
$main_int = 0; | |
$x = 0; | |
$factors = [ 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 ]; | |
foreach ( $cpr as $cpr_single_number ) { | |
$main_int += $cpr_single_number * $factors[ $x ]; | |
$x++; | |
} | |
return $main_int % 11 == 0; | |
} | |
function generate_cprs(){ | |
$result = []; | |
$date = "050287"; | |
$number = 0; | |
for ($x = 0; $x < 10; $x ++) { | |
for($y = 0; $y < 10; $y ++){ | |
for($z = 0; $z < 10; $z ++){ | |
for($i = 0; $i < 10; $i ++){ | |
$cpr = trim($date . $x . $y . $z . $i); | |
echo $cpr . "\n"; | |
if(validate_cpr_number($cpr)){ | |
array_push($result, $cpr); | |
} | |
} | |
} | |
} | |
} | |
return $result; | |
} | |
print_r(generate_cprs()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment