-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharr.class.php
More file actions
47 lines (43 loc) · 1.15 KB
/
arr.class.php
File metadata and controls
47 lines (43 loc) · 1.15 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
<?php
class arr {
/**
* Get an item from an array.
*
* "Dot" notation may be used to dig deep into the array.
*
* <code>
* // Get the $array['user']['name'] value from the array
* $name = arr::get($array, 'user.name');
* </code>
*
* @param array $array Array to retrieve item from
* @param string $key Key to retrieve value from
* @return array Array of retrieved values
*/
public static function get($array, $key) {
foreach (explode('.', $key) as $element) {
$array = $array[$element];
}
return $array;
}
/**
* Search an array for a specific term.
* Search is case-insensitive.
*
* Differs from PHP in_array function by allowing partial strings to be matched
*
* @param array $array Array to be searched
* @param string $searchTerm String to be searched for
* @return boolean True if string is found, false if not
*/
public static function search($array, $searchTerm) {
foreach ($array as $value) {
$value = strtolower($value);
$searchTerm = strtolower($searchTerm);
if (strpos($value, $searchTerm)) {
return true;
}
}
return false;
}
}