我目前正在努力比较两个数组。
第一个数组($allRoepnummerArray(包含所有可用的调用号。
第二个数组($occupiedRoepnummers(包含被占用的呼叫号码。
目前我无法将它们进行比较。
我想把可用的电话号码放在一张表里。
$allRoepnummerArray = array(
'22-101',
'22-102',
'22-103',
'22-104',
'22-105',
'22-106',
'22-107',
'22-108',
'22-109',
'22-110',
'22-111',
'22-112',
'22-113',
'22-114',
'22-115',
'22-116',
'22-117',
'22-118',
'22-119',
'22-120',
'22-121',
'22-122',
'22-123',
'22-124',
'22-125',
'22-126',
'22-127',
'22-128',
'22-129',
'22-130',
);
$occupiedRoepnummers = array();
foreach ($roepnummerResults as $roepnummerKey => $roepnummerValue) {
array_push($occupiedRoepnummers, $roepnummerValue['roepnummer']);
}
foreach($allRoepnummerArray as $allRoepnummer) {
foreach($occupiedRoepnummers as $occupiedRoepnummer) {
if ($allRoepnummer != $occupiedRoepnummer) {
echo '<th>'.$allRoepnummer.'</th>';
}
}
}
?>
您可以使用array_diff((减去数组。在你的情况下,你可以做:
$availableRoepnummers = array_diff($allRoepnummerArray, $occupiedRoepnummers);
然后,您可以制作一个$availableRoepnummers
的HTML表。
试试这个:
foreach($allRoepnummerArray as $allRoepnummer) {
if (!in_array($allRoepnummer,$occupiedRoepnummers)) {
echo '<th>'.$allRoepnummer.'</th>';
}}
使用下面这样的array_entersect((函数,它将只检索匹配的值
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");
$result= array_intersect($a1,$a2);
print_r(array_diff($a1,$result));
结果:Array ( [b] => green [c] => blue [d] => yellow )