Skip to content

Instantly share code, notes, and snippets.

@coquer
Created January 5, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coquer/7c28b9f7b49029cef46d to your computer and use it in GitHub Desktop.
Save coquer/7c28b9f7b49029cef46d to your computer and use it in GitHub Desktop.
<?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