1--TEST--
2Test array_any() function : basic functionality
3--FILE--
4<?php
5$array1 = [
6    "a" => 1,
7    "b" => 2,
8    "c" => 3,
9    "d" => 4,
10    "e" => 5,
11];
12
13$array2 = [
14    1, 2, 3, 4, 5
15];
16
17function even($input) {
18  return $input % 2 === 0;
19}
20
21class EvenClass {
22    public static function even($input) {
23        return $input % 2 === 0;
24    }
25}
26
27
28var_dump(array_any($array1, fn($value) => $value > 3));
29var_dump(array_any($array2, fn($value) => $value > 3));
30var_dump(array_any($array2, fn($value) => $value > 5));
31var_dump(array_any([], fn($value) => true));
32var_dump(array_any($array1, fn($value, $key) => $key === "c"));
33var_dump(array_any($array1, fn($value, $key) => false));
34
35echo '*** Test Exception after true result ***' . PHP_EOL;
36try {
37    var_dump(array_any($array2, function ($value) {
38        if ($value > 1) {
39            throw new Exception("Test-Exception");
40        }
41
42        return true;
43    }));
44} catch (Exception) {
45    var_dump("Unexpected Exception");
46}
47
48echo '*** Test aborting with exception ***' . PHP_EOL;
49try {
50    var_dump(array_any($array2, function ($value) {
51        if ($value === 2) {
52            throw new Exception("Test-Exception");
53        }
54
55        var_dump($value);
56
57        return false;
58    }));
59} catch (Exception) {
60    var_dump("Catched Exception");
61}
62
63var_dump(array_any($array1, 'even'));
64
65var_dump(array_any($array1, function($value) {
66    // return nothing
67}));
68
69var_dump(array_any($array1, [
70    'EvenClass',
71    'even'
72]));
73
74var_dump(array_any($array1, "EvenClass::even"));
75?>
76--EXPECT--
77bool(true)
78bool(true)
79bool(false)
80bool(false)
81bool(true)
82bool(false)
83*** Test Exception after true result ***
84bool(true)
85*** Test aborting with exception ***
86int(1)
87string(17) "Catched Exception"
88bool(true)
89bool(false)
90bool(true)
91bool(true)
92