选择语言 :

 Core_Arr::set_path

Set a value on an array by path.

null Core_Arr::set_path( array & $array , string $path , mixed $value [, string $delimiter = null ] )
see
Arr::path()

参数列表

参数 类型 描述 默认值
$array array Array to update
$path string Path
$value mixed Value to set
$delimiter string Path delimiter null
File: ./core/classes/arr.class.php
public static function set_path( &$array, $path, $value, $delimiter = null)
{
	if (!$delimiter)
	{
		// Use the default delimiter
		$delimiter = Arr::$delimiter;
	}

	// Split the keys by delimiter
	$keys = explode($delimiter, $path);

	// Set current $array to inner-most array path
	while (count($keys) > 1)
	{
		$key = array_shift($keys);

		if (ctype_digit($key))
		{
			// Make the key an integer
			$key = (int) $key;
		}

		if (!isset($array[$key]))
		{
			$array[$key] = array();
		}

		$array = & $array[$key];
	}

	// Set key on inner-most array
	$array[array_shift($keys)] = $value;
}