2 Test array_diff_key() function : error conditions
5 /* Prototype : array array_diff_key(array arr1, array arr2 [, array ...])
6 * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments.
7 * Source code: ext/standard/array.c
10 echo "*** Testing array_diff_key() : error conditions ***\n";
12 // Initialise the variables
13 $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
15 // Testing array_diff_key with one less than the expected number of arguments
16 echo "\n-- Testing array_diff_key() function with less than expected no. of arguments --\n";
18 var_dump( array_diff_key($array1) );
19 } catch (TypeError $e) {
20 echo $e->getMessage(), "\n";
23 // Testing array_diff_key with no arguments
24 echo "\n-- Testing array_diff_key() function with no arguments --\n";
26 var_dump( array_diff_key() );
27 } catch (ArgumentCountError $e) {
28 echo $e->getMessage(), "\n";
32 *** Testing array_diff_key() : error conditions ***
34 -- Testing array_diff_key() function with less than expected no. of arguments --
35 At least 2 parameters are required, 1 given
37 -- Testing array_diff_key() function with no arguments --
38 At least 2 parameters are required, 0 given