diff --git a/project.php b/project.php new file mode 100644 index 0000000..cd09bf4 --- /dev/null +++ b/project.php @@ -0,0 +1,48 @@ += 10) { + $card[$i] = $card[$i] % 10 + intdiv($card[$i],10); + } + } + + $isValid = (array_sum($card) % 10 == 0) ? "true" : "false"; + + return ["isValid" => $isValid]; + +} + +function PaymentSystem($card) { + + $paymentSystem = ["4" => "VISA", + "5"=>"Mastercard ", + "220"=>"MIR"]; + + if (array_key_exists($card[0], $paymentSystem)) { + $paymentSystem = $paymentSystem[$card[0]]; + } + elseif (array_key_exists(substr($card, 0, 3), $paymentSystem)){ + $paymentSystem = $paymentSystem[substr($card, 0, 3)]; + } + else { + $paymentSystem = "UNKNOWN"; + } + + return ["paymentSystem" => $paymentSystem]; +} + +$numberCard = readline("Введите номер карты:"); + +$newNumberCard = str_replace(' ','',$numberCard); +$mas = array(); + +for ($i = 0; $i < strlen($newNumberCard); $i++) { + $mas[$i] = (int)($newNumberCard[$i]); +} + +print_r(IsValid($mas)); +print_r(PaymentSystem($numberCard)); +?> \ No newline at end of file