dongliu4320 2014-05-21 08:52
浏览 55
已采纳

数组 - 删除重复/无密钥

Trying to learn how to work with Arrays, merging (or removing duplicate). Basically this: The database will have the actual data and I have another array that will give me all the result I expected to have.

Database:

V1, V2, V5, V6, V7, V10

Custom Array:

V1, V2, V3, V4, V5, V6, V7, V8, V9, V10

I would like to have the output to tell me:

V3, V4, V8, V9

But I keep getting only V1 as the output. I must've missed some vital information somewhere.

Example code I have:

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);

Any help/insight appreciated!

  • 写回答

2条回答 默认 最新

  • donte1234567 2014-05-21 08:57
    关注

    try this

    $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);
    

    OUTPUT :

    Array
    (
        [2] => V3
        [3] => V4
        [7] => V8
        [8] => V9
    )
    

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改