array_intersect_ukey function in php || php arrays
×


array_intersect_ukey function in php

1943

array_intersect_ukey() function of PHP is used to create a new array by matching the keys of two or more arrays with the help of a user define function or callback function. It is an inbuilt function of PHP.

Syntax:

array_intersect_ukey ($arr1,$arr2,.....$arrN,callback_function);

Here,

$arr1,$arr2 and $arrN are PHP arrays and callback_function is a user define function which campare the keys and return TRUE or FALSE.


Example 1:

<?php
function callback_function($x,$y)
{
if ($x===$y)
  {
  return 0;
  }
  return ($x>$y)?1:-1;
}
$arr1= array("fruit1"=>"Apple","fruit2"=>"Banana","fruit3"=>"Orange","fruit4"=>"Pear");
$arr2= array("fruit5"=>"Banana","fruit6"=>"Banana","fruit3"=>"Orange","fruit4"=>"Litchi");
$result=array_intersect_ukey($arr1,$arr2,"callback_function");
echo "<pre>";
print_r($result);
?>

Output:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments