国产女人18毛片水真多18精品, 一区二区三区中文字-亚洲精品女国产, 欧美熟妇老熟妇88888久久久久, 一级毛片免费观看亚洲欧美国产精品,大波霸美女视频,日韩欧美激情V影院,熟女人伦21p,亚洲精品女国产,国产 乱子伦 在线

PHP數(shù)組的交集array-intersect()

時間:2025-10-21 05:28:33 php語言

PHP數(shù)組的交集array-intersect()

  求兩個數(shù)組的交集問題可以使用array_intersect(),array_inersect_assoc,array_intersect_key來實現(xiàn),其中array_intersect()函數(shù)是求兩個數(shù)的交集,就跟隨百分網(wǎng)小編一起去了解下吧,想了解更多相關信息請持續(xù)關注我們應屆畢業(yè)生考試網(wǎng)!

  返回一個交集共有元素的數(shù)組(只是數(shù)組值得比較)、array_intersect_assoc()函數(shù)是將鍵值和值綁定,一起比較交集部分、array_intersect_key()函數(shù)是將兩個數(shù)組的鍵值進行比較,返回鍵值交集的數(shù)組。

  但實際應用中也遇到了一些小問題,正如下:

  實例:

  復制代碼 代碼如下:

  <?PHP

  $array = array("red"=>"Red","green"=>"red4","Red15"=>"Red",7=>"Level","Width"=>"Red","azzzz1"=>"art","peak"=>158);

  $array1 = array("red"=>"Red2","greena"=>"red","Red15"=>"Red",7=>"Level","Width"=>"Red","azzzz"=>"art","peak"=>158);

  $num = array_intersect($array,$array1);

  print_r ($num);

  echo "<br />";

  $num = array_intersect_assoc($array,$array1);

  print_r($num);

  echo "<br />";

  $num = array_intersect_key($array,$array1);

  print_r ($num);

  ?>

  運行結果:

  復制代碼 代碼如下:

  Array ( [red] => Red [Red15] => Red [7] => Level [Width] => Red [azzzz1] => art [peak] => 158 )

  Array ( [Red15] => Red [7] => Level [Width] => Red [peak] => 158 )

  Array ( [red] => Red [Red15] => Red [7] => Level [Width] => Red [peak] => 158 )

  總結:

  1.array_intersect()函數(shù)進行的比較只有數(shù)組值的比較,而且存在如”Red“和”Red2“比較時會返回"Red",反之則不會返回"Red2";

  2.array_intersect_assoc()函數(shù)是將數(shù)組的值與鍵值一起比較,而且不會存在array_intersect的情況,適用于較嚴格的比較;

  3.array_intersect_key()函數(shù)適用于比較兩個數(shù)組鍵值的交集,返回的并不只有鍵值,而是鍵值和對應的數(shù)組值。

【PHP數(shù)組的交集array-intersect()】相關文章:

PHP技巧:數(shù)組交集的優(yōu)化11-27

php數(shù)組操作如何實現(xiàn)鍵名比較與差集、交集賦值03-14

PHP數(shù)組的排序03-08

PHP一般數(shù)組與對象數(shù)組12-11

PHP數(shù)組基本介紹02-28

PHP數(shù)組函數(shù)知識10-13

簡單PHP數(shù)組函數(shù)介紹12-07

關于PHP數(shù)組函數(shù)知識01-15

php中數(shù)組的定義方法11-11