怎样快速找出两个数组中相同的元素?
例如我有两个数组
1、('csdn','php','asp','msdn','c#','java','jsp','vb')
2、('javajia','asp','java','source','c#','delphi','jsp','vc++')
快速找出两个数组中相同的元素,要快速,不能一个个遍历,因为有几千个元素呢。
如上两个数组,得出结果是('asp','java','c#','jsp')
100分敬上!先谢了!!
------解决方案--------------------
你试试用正则表达式!
如还有其他需要请留言!
------解决方案--------------------
<br /><br />$a=array('csdn','php','asp','msdn','c#','java','jsp','vb');<br />$b=array('javajia','asp','java','source','c#','delphi','jsp','vc++');<br /><br />print_r(array_intersect($a,$b));<br />
//效率不知道怎么样
------解决方案--------------------
楼上正解!
------解决方案--------------------
求两个数组的交集
<br />$a=array('csdn','php','asp','msdn','c#','java','jsp','vb');<br />$b=array('javajia','asp','java','source','c#','delphi','jsp','vc++');<br />print_r(array_intersect($a,$b));<br />
还不明白去查下手册array_intersect的用法
------解决方案--------------------
对啊,就这个函数就可以了
------解决方案--------------------
+1
------解决方案--------------------
计算两数组的交集
------解决方案--------------------
仅需要取相同的值时,可以用array_intersect()如果连键名也需要比较时用array_intersect_assoc()
------解决方案--------------------
就是用这个函数,系统函数比自定义的效率要高很多
------解决方案--------------------
1楼正解
------解决方案--------------------
我想来捞分的 没想到3楼太犀利。。。 正解
如果是C++ 我还有更犀利的方法 嘿嘿
------解决方案--------------------
3楼正解啊~~ 同样学习一下
------解决方案--------------------
3楼给力,学习了。
------解决方案--------------------
我也来默写一遍:array_intersect()
哈哈,记住了。。。。

标题:C#中使用Array.Sort函数对数组进行排序的示例正文:在C#中,数组是一种常用的数据结构,经常需要对数组进行排序操作。C#提供了Array类,其中有Sort方法可以方便地对数组进行排序。本文将演示如何使用C#中的Array.Sort函数对数组进行排序,并提供具体的代码示例。首先,我们需要了解一下Array.Sort函数的基本用法。Array.So

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

在进行PHP编程时,我们常常需要对数组进行合并。PHP提供了array_merge()函数来完成数组合并的工作,不过当数组中存在相同的键时,该函数会覆盖原有的值。为了解决这个问题,PHP在语言中还提供了一个array_merge_recursive()函数,该函数可以合并数组并保留相同键的值,使得程序的设计变得更加灵活。array_merge

在PHP中,有许多强大的数组函数可以使数组的操作更加方便和快捷。当我们需要将两个数组拼成一个关联数组时,可以使用PHP的array_combine函数来实现这一操作。这个函数实际上是用来将一个数组的键作为另一个数组的值,合并成一个新的关联数组。接下来,我们将会讲解如何使用PHP中的array_combine函数将两个数组拼成关联数组。了解array_comb

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
