| @@ 105-120 (lines=16) @@ | ||
| 102 | * @return array|bool The new array if the key exists, FALSE otherwise. |
|
| 103 | * @see array_insert_after() |
|
| 104 | */ |
|
| 105 | protected function insertBefore($key, &$array, $new_key, $new_value) |
|
| 106 | { |
|
| 107 | if (array_key_exists($key, $array)) { |
|
| 108 | $new = []; |
|
| 109 | foreach ($array as $k => $value) { |
|
| 110 | if ($k === $key) { |
|
| 111 | $new[$new_key] = $new_value; |
|
| 112 | } |
|
| 113 | $new[$k] = $value; |
|
| 114 | } |
|
| 115 | ||
| 116 | return $new; |
|
| 117 | } |
|
| 118 | ||
| 119 | return false; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * Inserts a new key/value after the key in the array. |
|
| @@ 135-150 (lines=16) @@ | ||
| 132 | * An value to insert. |
|
| 133 | * @return Collection|bool The new array if the key exists, FALSE otherwise. |
|
| 134 | */ |
|
| 135 | protected function insertAfter($key, Collection &$array, $new_key, $new_value) |
|
| 136 | { |
|
| 137 | if ($array->has($key)) { |
|
| 138 | $new = []; |
|
| 139 | foreach ($array as $k => $value) { |
|
| 140 | $new[$k] = $value; |
|
| 141 | if ($k === $key) { |
|
| 142 | $new[$new_key] = $new_value; |
|
| 143 | } |
|
| 144 | } |
|
| 145 | ||
| 146 | return collect($new); |
|
| 147 | } |
|
| 148 | ||
| 149 | return false; |
|
| 150 | } |
|
| 151 | ||
| 152 | /** |
|
| 153 | * Добавление глобальной переменной. |
|