3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NIP { private const WEIGHTS = [6, 5, 7, 2, 3, 4, 5, 6, 7]; private const NIP_MODULO = 11; private const INVALID_CHECKSUM = 10; public static function validate(string $nip): bool { $value = preg_replace('/[\s-]/', '', $nip); if ('0000000000' === $value || !preg_match('/^\d{10}$/', $value)) { return false; } $checkSum = self::getChecksum($value); if (self::INVALID_CHECKSUM === $checkSum || $checkSum !== ((int) (substr($value, -1)))) { return false; } return true; } private static function getChecksum(string $nip): int { $sum = 0; foreach (self::WEIGHTS as $key => $weight) { $sum += $weight * ((int) $nip[$key]); } return $sum % self::NIP_MODULO; } } $nip_numbers = array( "1234567890", "5366239267", "1071206063", "1160045242", "8123035307", "5361869035", "9322423343", "1191232175", "1079704010", "1560650337" ); $c = new NIP(); foreach ($nip_numbers as $a) { var_dump($c->validate($a)); }
Output for git.master_jit, git.master
bool(false) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)

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:
29.74 ms | 405 KiB | 5 Q