PHP Programing language

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

array_intersect()

The array_intersect() function compares the values of two or more arrays, and returns the match values.

Syntax:
array_intersect(array1,array2,array3...);

In above Syntax,"array1" compare from, "array2" compare against,"array3" compare against to more arrays.

Example:

<?php
$array1=array("a"=>"Apple","b"=>"Banana","c"=>"Orange","d"=>"Mango");
$array2=array("e"=>"Apple","f"=>"Banana","g"=>"Orange");
$result=array_intersect($array1,$array2);
print_r($result);
?>

Output:

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

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

array_intersect_assoc()

The array_intersect_assoc() function compares the keys and values of two or more arrays, and returns the match values.

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

In above Syntax,"array1" compare from, "array2" compare against,"array3" compare against to more arrays.

Example:

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

Output:

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

array_intersect_uassoc()

The array_intersect_uassoc() function compares the keys and values of two or more arrays, and returns the match values.

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

In above Syntax,"array1" compare from, "array2" compare against, "array3" compare against to more arrays 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;
}
$array1=array("a"=>"Apple","b"=>"Mango","c"=>"Orange");
$array2=array("d"=>"Apple","b"=>"Mango","e"=>"Orange");
$result=array_intersect_uassoc($array1,$array2,"myfunction");
print_r($result);
?>

Output:

Array ( [b] => Mango )

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

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