尝试学习如何使用数组,合并(或删除重复)。基本上这个:数据库将包含实际数据,我有另一个数组,它将给出我预期的所有结果。
数据库:
V1
,V2
,V5
,V6
,V7
,V10
自定义数组:
V1
,V2
,V3
,V4
,V5
,V6
,V7
,V8
,V9
,V10
我想让输出告诉我:
V3
,V4
,V8
,V9
但我一直只获得V1
作为输出。我必须在某处错过一些重要信息。
我的示例代码:
for($x = 0; $x < 1201; $x++){ $a[] = array('VFL'.$x); }
$MFSQL = 'SELECT SCPlayer FROM SC'.$S;
$MFSQL .= ' WHERE SCSnap = (SELECT MAX(DSSnap) FROM DataSnap WHERE DSServer = '.$S.')';
$MFSQL .= ' AND (SCPlayer REGEXP "VFL[0-9]{1,4}")';
$MFSQL .= ' ORDER BY SCPlayer';
$Re = $ZD -> query($MFSQL);
while($Ro = $ZD -> fetch_assoc($Re)){ $b[] = array($Ro['SCPlayer']); }
$c = array_values(array_unique($a+$b));
echo json_encode($c);
感谢任何帮助/见解!
答案 0 :(得分:1)
您可以使用array_diff:
$arr = array_diff($custom, $database);
答案 1 :(得分:1)
试试这个
$arr_database = array("V1", "V2", "V5", "V6", "V7", "V10");
$arr_custom = array("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10");
$arr_output = array_diff($arr_custom, $arr_database);
print_r($arr_output);
输出:
Array
(
[2] => V3
[3] => V4
[7] => V8
[8] => V9
)
<强> DEMO 强>