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 | foreach ($array as $key => $element) { |
|
44 | 1 | if ($key !== $elementName) { |
|
45 | 1 | if (!is_array($element)) { |
|
46 | 1 | return []; |
|
47 | } |
||
48 | $result = $this->findElement($element, $elementName); |
||
49 | if ($result) { |
||
50 | return $result; |
||
51 | } |
||
52 | } else { |
||
53 | return $element; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | return []; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param array $array |
||
62 | * @param string $searchKey |
||
63 | * @return array |
||
64 | */ |
||
65 | public function findByContainedKey(array $array, $searchKey) |
||
76 | |||
77 | /** |
||
78 | * @param array $array |
||
79 | * @param string $searchKey |
||
80 | * @param array $keyChains |
||
81 | * @return array |
||
82 | */ |
||
83 | protected function findKeyChainsContainingKey(array $array, $searchKey, array $keyChains, $keyChain) |
||
101 | } |
||
102 |