PHP Programing language

R4R® PHP
(追記) (追記ここまで)
(追記) (追記ここまで)
array_intersect_key() Functions in PHP
(追記) (追記ここまで)
(追記) (追記ここまで)

array_intersect_key()

The array_intersect_key() function compares the keys of two or more arrays, and return an array that contains the entries from any array1 that are present in any array2, array3, and so on.

Syntax:
array_intersect_key(array1,array2,array3...)

In above syntax,"array1" is the array that the others will be compared with "array2" is the array to be compared with the first array "array3,..." is the array to be compared with the first array

Example:

<?php
$array1=array("a"=>"Apple","b"=>"Banana","c"=>"Mango");
$array2=array("a"=>"Apple","c"=>"Banana","d"=>"Mango");
$result=array_intersect_key($array1,$array2);
print_r($result);
?>

Output:

Array ( [a] => Apple [c] => Mango )

(追記) (追記ここまで)

array_intersect_ukey()

array_intersect_key() compares the keys of two or more arrays, and return an array that contains the entries from any array1 that are present in any array2, array3, and so on.

Syntax:
array_intersect_ukey(array1,array2,array3...,myfunction)

In above syntax,"array1" is the array that the others will be compared with "array2" is the array to be compared with the first array "array3,..." is the array to be compared with the first array and "myfunction" is a string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Example:

<?php
function myfunction($a,$b)
{
if ($a===$b)
 {
 return 0;
 }
 return ($a>$b)?1:-1;
}
$a1=array("a"=>"Apple","b"=>"Banana","c"=>"Orange");
$a2=array("a"=>"Orange","b"=>"Mango","e"=>"Orange");
$result=array_intersect_ukey($a1,$a2,"myfunction");
print_r($result);
?>

Output:

Array ( [a] => Apple [b] => Banana )

(追記) (追記ここまで)
Copyright ©2021-22 r4r.co.in, all rights reserved. Theguestspost.com
Sitemap
Career
Post comment
About us
Subscription
Unsubscription

AltStyle によって変換されたページ (->オリジナル) /