PHP实现查询两个数组中不同元素的方法

以下实例讲述了PHP实现查询两个数组中不同元素的方法。分享给大家供大家参考,具体如下:

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

<?php

  $a = array(

  "max_allow_dialogs",

  "livechat_server_ip",

  "livechat_service_time",

  "abort_zh_cn",

  "abort_zh_tw",

  "abort_en_usa",

  "welcome_zh_cn",

  "welcome_zh_tw",

  "welcome_en_usa",

  "timeout_zh_cn",

  "timeout_zh_tw",

  "timeout_en_usa",

  "absence_zh_cn",

  "absence_zh_tw",

  "absence_en_usa"

  );

  $b = array(

  "max_allow_dialogs",

  "livechat_server_ip",

  "livechat_service_time",

  "abort_zh_cn",

  "abort_zh_tw",

  "abort_en_usa",

  "welcome_zh_cn",

  "welcome_zh_tw",

  "welcome_en_usa",

  "timeout_zh_cn",

  "timeout_zh_tw",

  "timeout_en_usa",

  );

  $c = array_merge(array_diff($a,$b),array_diff($b,$a));

  print_r($c);

?>

结果:

Array

(

  [0] => absence_zh_cn

  [1] => absence_zh_tw

  [2] => absence_en_usa

)

原文地址:https://www.cnblogs.com/applelife/p/10811907.html

时间: 2024-08-06 02:20:33

PHP实现查询两个数组中不同元素的方法的相关文章

Java比较两个数组中的元素是否相同的最简单方法

呵呵呵,实现Java比较两个数组中的元素是否相同的功能你是怎么做的?看下面最简单方法: import java.util.Arrays; public class Test { /** * Java比较两个数组中的元素是否相同 */ public static void main(String[] args) { String [] array1 = {"1","2","3"}; String [] array2 = {"3"

Java对数组的操作(三)—比較两个数组中的元素是否同样的最简单方法

呵呵呵,实现Java比較两个数组中的元素是否同样的功能你是怎么做的?看以下最简单方法: import java.util.Arrays; public class Test { /**                 * Java比較两个数组中的元素是否同样                 */                public static void main(String[] args) {                        String [] array1 = {"1

提取两个数组中不同元素

假设数组: string[] listA ={"1","2","3","4","5"}; string[] listB = {"1","4","5"}; 那么,提取两个数组中不同的元素放到另一个数组中:代码如下: string[] result = listA.Except(listB).Union(listB.Except(listB)).ToA

几种去除数组中重复元素的方法

工作中遇到的一个问题,就是去除数组中重复的元素,记录一下几种有效的方法: 第一种思路:遍历要删除的数组arr, 把元素分别放入另一个数组tmp中,在判断该元素在arr中不存在才允许放入tmp中. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>去除数组重复项</title> </head> &

统计两个数组中相同元素的个数

import numpy as np import tensorflow as tf A = [1,3,4,5,6,1,2,3,4,5] B = [1,3,4,3,2,2,2,3,4,3] with tf.Session() as sess: a=sess.run(tf.equal(A, B)) b=a.tolist().count(True) print(a.tolist()) print(b) 原文地址:https://www.cnblogs.com/Ann21/p/11107864.htm

26、删除有序数组中的元素,数组仍然有序

删除有序数组中的元素,数组仍然有序 方法一: 删除一个有序数组的一个元素,采用两个数组实现 代码实现: /* 2017年6月19日16:16:31 功能:删除数组中一个数据之后数组依然有序 */ #include"stdio.h" #define M 9 int main() { int a[M] = {1,2,3,4,5,6,7,8,9}; int b[M-1]; int i, j, num; bool flag; printf("请输入将要删除的数据的数值:")

C语言:返回两个数组中第一个元素的指针,并输出这个值

// //  main.c //  Pointer_search // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年 bjsxt. All rights reserved. //  要求:通过指针查找,实现比较两个有序数组中的元素,输出两个数组中的第一个相同的元素值. #include <stdio.h> int *searchSameElement(int *a,int *b,int len1,int len2); int ma

有两数组A、B,长度分别为m、n。用不超过m+n的比较次数找到两个数组中的相同元素

今天碰到一道笔试题:有两数组A.B,长度分别为m.n.用不超过m+n的比较次数找到两个数组中的相同元素.当时没做出来,我现在给出C#版本,算是弥补一点遗憾. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SortAB { class Program { static void Main(string[] args) { int[] A = Random

C 语言:返回两个数组中第一个相同元素的指针(我用了loop 、goto loop标签)

// //  main.c //  Pointer_search // //  Created by ma c on 15/8/2. //  Copyright (c) 2015年 bjsxt. All rights reserved. //  要求:通过指针查找,实现比较两个有序数组中的元素,输出两个数组中的第一个相同的元素值. #include <stdio.h> int *searchSameElement(int *a,int *b,int len1,int len2); int ma