日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

intersect函数_PHP array_intersect()函数与示例

發布時間:2023/12/1 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 intersect函数_PHP array_intersect()函数与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

intersect函數

PHP array_intersect()函數 (PHP array_intersect() Function )

array_intersect() function is used to find the matched elements from two or more elements. Function “array_intersect()” compares the values of the first array with the other arrays and returns matched elements.

array_intersect()函數用于從兩個或多個元素中查找匹配的元素。 函數“ array_intersect()”將第一個數組的值與其他數組進行比較,并返回匹配的元素。

Syntax:

句法:

array_intersect(array1, array2, [array3,...]);

Here, array1, array2 are the input arrays other arrays are an optional.

在這里, array1 , array2是輸入數組,其他數組是可選的。

Examples:

例子:

Input:$arr1 = array("Hello", "Hi", "Okay", "Bye!");$arr2 = array("Okay", "Hello", "Bye", "Hi");Function calling: array_intersect($arr1, $arr2);Output:Array([0] => Hello[1] => Hi[2] => Okay)

PHP code 1: Comparing two string arrays.

PHP代碼1:比較兩個字符串數組。

<?php//input array1 $arr1 = array("Hello", "Hi", "Okay", "Bye!");//input array2$arr2 = array("Okay", "Hello", "Bye", "Hi");//finding matched elements$ans = array_intersect($arr1, $arr2);print_r ($ans); ?>

Output

輸出量

Array ([0] => Hello[1] => Hi[2] => Okay )

PHP code 2:Comparing three arrays with strings & numbers.

PHP代碼2:將三個數組與字符串和數字進行比較。

<?php//input array1 $arr1 = array(10, 20, 30, "Hello", 40, "Hi", 50);//input array2$arr2 = array(50, 60, "Hello", 70, 80);//input array3$arr3 = array(10, 20, "Hello", 50, "Hi", 30);//finding matched elements$ans = array_intersect($arr1, $arr2, $arr3);print_r ($ans); ?>

Output

輸出量

Array ([3] => Hello[6] => 50 )

翻譯自: https://www.includehelp.com/php/array_intersect-function-with-example.aspx

intersect函數

總結

以上是生活随笔為你收集整理的intersect函数_PHP array_intersect()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。