1 | <?php |
||
15 | class Naming { |
||
16 | |||
17 | /** |
||
18 | * Parse usual HTML notation complex field name into array. |
||
19 | * |
||
20 | * @param string $fieldName Field name. |
||
21 | * |
||
22 | * @return mixed String or array. |
||
23 | */ |
||
24 | public static function parseComplexName($fieldName) { |
||
40 | |||
41 | /** |
||
42 | * Returns value of the complex array element by it's complex key. |
||
43 | * |
||
44 | * @param array $array Complex associated array (dictionary); |
||
45 | * @param mixed $complexName List with hierarchy complex key or a string |
||
46 | * value of complex or simple (one level) key. |
||
47 | * |
||
48 | * @return mixed Value of the array element if found. |
||
49 | * @throws \Exception If can't find element by complex key or no name provided. |
||
50 | */ |
||
51 | public static function getValueByComplexName($array, $complexName) { |
||
79 | |||
80 | /** |
||
81 | * Sets value of the complex array element by it's complex key. |
||
82 | * |
||
83 | * @param array $array Complex associated array (dictionary); |
||
84 | * @param mixed $complexName List with hierarchy complex key or a string |
||
85 | * value of complex or simple (one level) key. |
||
86 | * @param mixed $value Value. |
||
87 | * @param bool $rewrite Rewrite existed values with the same name tree or not. |
||
88 | * |
||
89 | * @throws \Exception If can't find element by complex key or no name provided. |
||
90 | */ |
||
91 | public static function setValueWithComplexName(&$array, $complexName, $value, $rewrite = false) { |
||
128 | |||
129 | /** |
||
130 | * Removes value of the complex array element by it's complex key. |
||
131 | * |
||
132 | * @param array $array Complex associated array (dictionary); |
||
133 | * @param mixed $complexName List with hierarchy complex key or a string |
||
134 | * value of complex or simple (one level) key. |
||
135 | * |
||
136 | * @throws \Exception If no name provided. |
||
137 | */ |
||
138 | public static function unsetValueWithComplexName(&$array, $complexName) { |
||
165 | |||
166 | /** |
||
167 | * Removes value of the complex array element by it's complex key. |
||
168 | * |
||
169 | * @param array $array Complex associated array (dictionary); |
||
170 | * @param mixed $complexName List with hierarchy complex key or a string |
||
171 | * value of complex or simple (one level) key. |
||
172 | * |
||
173 | * @throws \Exception If no name provided. |
||
174 | */ |
||
175 | public static function deleteValueWithComplexName(&$array, $complexName) { |
||
178 | |||
179 | /** |
||
180 | * Removes value of the complex array element by it's complex key. |
||
181 | * |
||
182 | * @param array $array Complex associated array (dictionary); |
||
183 | * @param mixed $complexName List with hierarchy complex key or a string |
||
184 | * value of complex or simple (one level) key. |
||
185 | * |
||
186 | * @throws \Exception If no name provided. |
||
187 | */ |
||
188 | public static function removeValueWithComplexName(&$array, $complexName) { |
||
191 | |||
192 | } |
||
193 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: