- array_intersect_key: documentation ( source)
- print_r: documentation ( source)
- ksort: documentation ( source)
- rand: documentation ( source)
<?php
function genRand($length = 10, $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $chars[rand(0, strlen($chars) - 1)];
}
return $randomString;
}
function populate($count = 10000) {
$array = array();
for($i = 0; $i < $count; $i++) {
$phone = genRand(10,'0123456789');
$array[$phone] = array(
'phone' => $phone,
'name' => genRand(20),
'age' => genRand(2, '0123456789'),
);
}
return $array;
}
$array1 = populate(40000);
$array2 = populate(40000);
ksort($array1);
ksort($array2);
$matched = array_intersect_key($array1, $array2);
print_r((!empty($matched) ? 'matched' : 'nope'));