1--TEST--
2Test array_intersect_ukey() function : usage variation - Passing class/object methods to callback
3--FILE--
4<?php
5/* Prototype  : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func)
6 * Description: Computes the intersection of arrays using a callback function on the keys for comparison.
7 * Source code: ext/standard/array.c
8 */
9
10echo "*** Testing array_intersect_ukey() : usage variation ***\n";
11
12//Initialise arguments
13$array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);
14$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan'   => 8);
15
16class MyClass
17{
18	static function static_compare_func($key1, $key2) {
19		return strcasecmp($key1, $key2);
20	}
21
22	public function class_compare_func($key1, $key2) {
23		return strcasecmp($key1, $key2);
24	}
25
26}
27
28echo "\n-- Testing array_intersect_ukey() function using class with static method as callback --\n";
29var_dump( array_intersect_ukey($array1, $array2, array('MyClass','static_compare_func')) );
30var_dump( array_intersect_ukey($array1, $array2, 'MyClass::static_compare_func') );
31
32echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n";
33$obj = new MyClass();
34var_dump( array_intersect_ukey($array1, $array2, array($obj,'class_compare_func')) );
35?>
36===DONE===
37--EXPECTF--
38*** Testing array_intersect_ukey() : usage variation ***
39
40-- Testing array_intersect_ukey() function using class with static method as callback --
41array(2) {
42  ["blue"]=>
43  int(1)
44  ["green"]=>
45  int(3)
46}
47array(2) {
48  ["blue"]=>
49  int(1)
50  ["green"]=>
51  int(3)
52}
53
54-- Testing array_intersect_uassoc() function using class with regular method as callback --
55array(2) {
56  ["blue"]=>
57  int(1)
58  ["green"]=>
59  int(3)
60}
61===DONE===
62