Skip to main content

array_intersect_key()

<?php
function myfunction($a,$b)
{
if ($a===$b)
  {
  return 0;
  }
  return ($a>$b)?1:-1;
}

$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("d"=>"red","b"=>"green","e"=>"blue");

$result=array_intersect_uassoc($a1,$a2,"myfunction");
print_r($result);
?>


Output:
Array ( [b] => green )

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

Comments

Popular posts from this blog

PHP array_column() Function

  <?php // An array that represents a possible record set returned from a database $a =  array (    array (      'id'  =>  5698 ,      'first_name'  =>  'Mehran' ,      'last_name'  =>  'Yaqoob' ,   ),    array (      'id'  =>  4767 ,      'first_name'  =>  'Muneeb' ,      'last_name'  =>  'Ahmad' ,   ),    array (      'id'  =>  3809 ,      'first_name'  =>  'Uzair' ,      'last_name'  =>  'Rajput' ,   ) ); $last_names = array_column($a,  'last_name' ); print_r($last_names); ?> Output: Array (   [0] => Yaqoob   [1] => Ahmad   [2] => Rajput ) Syntex: array_column( array ,  column_key ,  index_key ...

Mastering PHP's array_merge(): When to Use It (And When Not To)

Pros, Cons, and Best Practices PHP's  array_merge()  function is one of the most commonly used array functions in web development. Whether you're building a simple website or a complex web application, understanding how to effectively merge arrays can save you time and prevent headaches. In this comprehensive guide, we'll explore everything you need to know about  array_merge() , including its advantages, limitations, practical use cases, and alternatives. What is  array_merge()  in PHP? array_merge()  is a built-in PHP function that combines two or more arrays into a single array. The function takes multiple array arguments and returns a new array containing all the elements from the input arrays. Basic Syntax php array_merge ( array ... $arrays ) : array Simple Example php $array1 = [ 'a' , 'b' , 'c' ] ; $array2 = [ 'd' , 'e' , 'f' ] ; $result = array_merge ( $array1 , $array2 ) ; print_r ( $result ) ; /* O...