Ds \ Map::diff()函數是PHP中的一個內置函數,用於使用包含第一張Map中未包含在另一張Map中的元素的鍵創建Map。
用法:
Ds\Map public Ds\Map::diff( $map )
參數:該函數接受單個參數$map,該參數用於保存需要排除其值的map元素。
返回值:它會返回一個新Map,其中包含第一張Map中另一個Map中不存在的元素。
以下示例程序旨在說明PHP中的Ds \ Map::diff()函數:
程序1:
<?php
// PHP program to illustrate the diff()
// function of Ds\map
// Creating a Map
$map1 = new \Ds\Map(["1" => "10",
"3" => 30, "4" => 40]);
// Creating another Map
$map2 = new \Ds\Map(["2" => "20",
"3" => 35, "5" => 50, "6" => 60]);
echo "Difference between two map:<br>";
print_r($map1 -> diff($map2));
?>
輸出:
Difference between two map:
Ds\Map Object ( [0] => Ds\Pair Object ( [key] => 1 [value] => 10 ) [1] => Ds\Pair Object ( [key] => 4 [value] => 40 ) )
程序2:
<?php
// PHP program to illustrate the diff()
// function of Ds\map
// Creating a Map
$map1 = new \Ds\Map([
"1" => "Geeks",
"2" => "for",
"3" => "Geeks"]);
// Creating another Map
$map2 = new \Ds\Map([
"2" => "for",
"3" => "Geeks",
"4" => "GeeksforGeeks"]);
echo "Difference between two map:<br>";
print_r($map1 -> diff($map2));
?>
輸出:
Difference between two map:
Ds\Map Object ( [0] => Ds\Pair Object ( [key] => 1 [value] => Geeks ) )
參考: https://www.php.net/manual/en/ds-map.diff.php
相關用法
- PHP Ds\Set diff()用法及代碼示例
- PHP DateTime diff()用法及代碼示例
- p5.js arc()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js cos()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP each()用法及代碼示例
- PHP dir()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- PHP min( )用法及代碼示例
- p5.js max()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | Ds\Map diff() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。