-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c9583c
commit a5ddd30
Showing
4 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
|
||
namespace Akademiano\Config; | ||
|
||
|
||
class ConfigTools | ||
{ | ||
/** | ||
* @param array | ||
* @param array | ||
* @return array | ||
*/ | ||
public static function merge() | ||
{ | ||
$arrays = func_get_args(); | ||
$merged = array_shift($arrays); | ||
foreach ($arrays as $currentArray) { | ||
foreach ($currentArray as $key => $value) { | ||
if (is_array($value) && isset ($merged[$key]) && is_array($merged[$key])) { | ||
$merged[$key] = self::merge($merged[$key], $value); | ||
} else { | ||
//проверяем что это не отключение параметров | ||
$unSetted = false; | ||
if ($value === null && !is_integer($key)) { | ||
if (false !== $keyMerged = array_search($key, $merged)) { | ||
if (is_integer($keyMerged)) { | ||
unset($merged[$keyMerged]); | ||
$unSetted = true; | ||
} | ||
} | ||
} | ||
if (!$unSetted) { | ||
//Числовой ключ добавляем, если такого значения нет, иначе заменяем | ||
if (is_integer($key) && is_string($value)) { | ||
if (!array_search($value, $merged)) { | ||
$merged[] = $value; | ||
} | ||
} else { | ||
$merged[$key] = $value; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return $merged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters