本文整理汇总了PHP中ArrayUtils::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::merge方法的具体用法?PHP ArrayUtils::merge怎么用?PHP ArrayUtils::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::merge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
public static function set($key, $value)
{
if (!self::exists($key)) {
$set = ArrayUtils::stringToNestedArray($key, $value);
self::$config = ArrayUtils::merge(self::$config, $set);
}
return false;
}
示例2: parseConfigFile
/**
* Parse a ini or php config file and keep typecasting.
*
* For ini files, this is similar to the parse_ini_file function, but keeps typecasting and require "" around strings.
* For php files this function will look for a variable called $config, and return it.
*
* @param string $filename the full path to the file to parse.
* @return mixed array or false. Array with the read configuration file, or false upon failure.
*/
public static function parseConfigFile($filename)
{
if (!is_readable($filename)) {
return false;
}
$return = array();
$lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines === false) {
return false;
}
if (!empty($lines)) {
foreach ($lines as $linenum => $linestr) {
if (substr($linestr, 0, 1) === ';') {
continue;
}
$line = explode(' = ', $linestr);
$key = trim($line[0]);
if (isset($line[1]) && substr($key, 0, 1) !== '[') {
if (isset($value)) {
unset($value);
}
if (substr($line[1], 0, 1) === '"' && substr($line[1], -1, 1) === '"') {
$value = str_replace(array('\\"', '\\\\'), array('"', '\\'), substr($line[1], 1, -1));
} elseif (ctype_digit($line[1]) || substr($line[1], 0, 1) === '-' && ctype_digit(substr($line[1], 1))) {
$num = $line[1];
if (substr($num, 0, 1) === '-') {
$num = substr($line[1], 1);
}
if (substr($num, 0, 1) === '0') {
if (substr($line[1], 0, 1) === '-') {
$value = -octdec($line[1]);
} else {
$value = octdec($line[1]);
}
} else {
$value = (int) $line[1];
}
unset($num);
} elseif ($line[1] === 'true') {
$value = true;
} elseif ($line[1] === 'false') {
$value = false;
} elseif ($line[1] === 'null') {
$value = null;
} elseif (preg_match('/^0[xX][0-9a-fA-F]+$/', $line[1])) {
$value = hexdec(substr($line[1], 2));
} elseif (preg_match('/^\\-0[xX][0-9a-fA-F]+$/', $line[1])) {
$value = -hexdec(substr($line[1], 3));
} elseif (preg_match('/^0b[01]+$/', $line[1])) {
$value = bindec(substr($line[1], 2));
} elseif (preg_match('/^\\-0b[01]+$/', $line[1])) {
$value = -bindec(substr($line[1], 3));
} elseif (filter_var($line[1], FILTER_VALIDATE_FLOAT) !== false) {
$value = (double) $line[1];
} elseif (defined($line[1])) {
$value = constant($line[1]);
} elseif (defined(__NAMESPACE__ . '\\' . $line[1])) {
$value = constant(__NAMESPACE__ . '\\' . $line[1]);
} else {
throw new \Exception('Unknown value in ini file on line ' . ($linenum + 1) . ': ' . $linestr);
}
if (isset($value)) {
if (!isset($lastkey)) {
$return[$key] = $value;
} else {
$return = ArrayUtils::merge($return, ArrayUtils::stringToNestedArray($lastkey, [$key => $value]));
}
}
} else {
$lastkey = substr($key, 1, -1);
}
}
}
return $return;
}
示例3: foreach
}
}
if (isset($value['regex']) && isset($matches)) {
foreach ($matches as $index => $match) {
if (is_int($index)) {
continue;
}
$value['path'] = str_replace('{' . $index . '}', $match, $value['path']);
}
}
define(__NAMESPACE__ . '\\BASE_PATH', $value['path'] . SUBSITE_PATH);
define(__NAMESPACE__ . '\\MAIN_BASE_PATH', $value['path']);
define(__NAMESPACE__ . '\\BASE_PATH_KEY', $key);
define(__NAMESPACE__ . '\\IS_SUBSITE', true);
if (is_readable(MAIN_SITE_DIR . 'config.php')) {
$subConfig = ArrayUtils::merge(include MAIN_SITE_DIR . 'config.php', $subConfig, true);
}
MainConfig::setAll($subConfig);
}
}
}
}
}
}
if (defined(__NAMESPACE__ . '\\IS_SUBSITE')) {
} elseif (!isset($config['base'])) {
throw new \Exception('No basepath set.');
} elseif (!is_array($config['base'])) {
throw new \Exception('Invalid basepath set.');
} elseif (is_array($config['base'])) {
define(__NAMESPACE__ . '\\IS_SUBSITE', false);
示例4: set
public function set($key, $value)
{
$this->params = ArrayUtils::merge($this->params, ArrayUtils::stringToNestedArray($key, $value));
}