1 | <?php |
||
12 | class ArrayService extends AbstractService |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Replace a key $replaceKey with $replaceItem |
||
17 | * |
||
18 | * @param array $array |
||
19 | * @param $replaceItem |
||
20 | * @param $replaceKey |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | 3 | public function replaceRecursiveByKey(array $array, $replaceItem, $replaceKey) |
|
35 | |||
36 | /** |
||
37 | * @param array $array |
||
38 | * @param string $elementName |
||
39 | * @return array |
||
40 | */ |
||
41 | 1 | public function findElement(array $array, $elementName) |
|
42 | { |
||
43 | 1 | if (array_key_exists($elementName, $array)) { |
|
44 | 1 | return $array[$elementName]; |
|
45 | } |
||
46 | |||
47 | 1 | foreach ($array as $key => $element) { |
|
48 | 1 | if (!is_array($element)) { |
|
49 | 1 | continue; |
|
50 | } |
||
51 | |||
52 | 1 | $result = $this->findElement($element, $elementName); |
|
53 | 1 | if ($result) { |
|
54 | 1 | return $result; |
|
55 | } |
||
56 | } |
||
57 | |||
58 | return []; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param array $array |
||
63 | * @param string $searchKey |
||
64 | * @return array |
||
65 | */ |
||
66 | public function findByContainedKey(array $array, $searchKey) |
||
77 | |||
78 | /** |
||
79 | * @param array $array |
||
80 | * @param string $searchKey |
||
81 | * @param array $keyChains |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function findKeyChainsContainingKey(array $array, $searchKey, array $keyChains, $keyChain) |
||
102 | } |
||
103 |