// A GUID (Globally Unique Identifier) and a UUID (Universally Unique Identifier)
// are essentially the same, both being 128-bit values used to uniquely identify
// information in computer systems.
// Generate a UUIDv4 (random)
function uuid_v4() {
$data = random_bytes(16);
// Set version to 4
$data[6] = chr((ord($data[6]) & 0x0f) | 0x40);
// Set variant to RFC 4122
$data[8] = chr((ord($data[8]) & 0x3f) | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
// Create an array containing three randomly generated UUIDs.
// uuid_v4() produces a type‑4 GUID.
$guids = [
uuid_v4(),
uuid_v4(),
uuid_v4()
];
// Compute a hash value for the entire set.
// hash('crc32b', ...) is idiomatic PHP for producing a simple 32‑bit hash.
$hash = hash('crc32b', implode('', $guids));
// Print the GUIDs so we can see what was hashed.
echo "GUIDs in the set:\n";
foreach ($guids as $g) {
echo $g . "\n";
}
// Print the resulting hash value.
echo "\nHash of the GUID set: $hash\n";
/*
run:
GUIDs in the set:
e68e7fc9-cb77-475b-ba64-8aee547897be
94289551-16a4-4607-b122-34f1977b5302
a550f47b-ea46-4b54-ade7-4a4ed3cc4cc5
Hash of the GUID set: a7d152e1
*/