-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
120 lines (110 loc) · 2.35 KB
/
code.power
File metadata and controls
120 lines (110 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Check if have an array with a length
*
* @input array The array to check
*
* @returns int|false number of items in array on success
*
* @since 3.2.0
*/
public static function check($array, $removeEmptyString = false)
{
if (is_array($array) && ($nr = count((array) $array)) > 0)
{
// also make sure the empty strings are removed
if ($removeEmptyString)
{
$array = array_filter($array);
if ($array === [])
{
return false;
}
return count($array);
}
return $nr;
}
return false;
}
/**
* Merge an array of array's
*
* @input array The arrays you would like to merge
*
* @returns array|null merged array on success
*
* @since 3.0.9
*/
public static function merge($arrays): ?array
{
if(self::check($arrays))
{
$merged = [];
foreach ($arrays as $array)
{
if (self::check($array))
{
$merged = array_merge($merged, $array);
}
}
return $merged;
}
return null;
}
/**
* Check if arrays intersect
*
* @input array The first array
* @input array The second array
*
* @returns bool true if intersect else false
*
* @since 3.1.1
*/
public static function intersect($a_array, $b_array): bool
{
// flip the second array
$b_array = array_flip($b_array);
// loop the first array
foreach ($a_array as $v)
{
if (isset($b_array[$v]))
{
return true;
}
}
return false;
}
/**
* Deep clone an array, including nested arrays and objects.
*
* This method creates a completely independent copy of the given array.
* It recursively clones nested arrays and uses PHP's `clone` keyword
* to clone any objects found within the structure.
*
* Note: Resources and closures are not supported and will not be copied.
*
* @param array $array The array to be deeply cloned.
*
* @return array A fully cloned, independent copy of the input array.
* @since 5.1.1
*/
public static function clone(array $array): array
{
$copy = [];
foreach ($array as $key => $value)
{
if (is_array($value))
{
$copy[$key] = self::clone($value);
}
elseif (is_object($value))
{
$copy[$key] = clone $value;
}
else
{
$copy[$key] = $value;
}
}
return $copy;
}