setByPath

@param mixed  &$data
@param string $path
@param mixed  $value
@param string $separator

@return  boolean

@since   2.0
177911
public static function setByPath(array &$data, $path, $value, $separator = '.')
    {
        $nodes = array_values(explode($separator, $path));

        if (empty($nodes)) {
            return false;
        }

        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (is_array($dataTmp)) {
                if ((string) $node === '') {
                    $tmp = [];
                    $dataTmp[] = &$tmp;
                    $dataTmp = &$tmp;
                } else {
                    if (empty($dataTmp[$node])) {
                        $dataTmp[$node] = [];
                    }

                    $dataTmp = &$dataTmp[$node];
                }
            } else {
                // If a node is value but path is not go to the end, we replace this value as a new store.
                // Then next node can insert new value to this store.
                $dataTmp = &$value;
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        $dataTmp = $value;

        return true;
    }
294500
public static function removeByPath(&$data, $path, $separator = '.')
    {
        $nodes = array_values(array_filter(explode($separator, $path), 'strlen'));

        if (empty($nodes)) {
            return false;
        }

        $previous = null;
        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (is_object($dataTmp)) {
                if (empty($dataTmp->$node)) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp->$node;
            } elseif (is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp[$node];
            } else {
                return false;
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        if (is_object($previous)) {
            unset($previous->$node);
        } elseif (is_array($previous)) {
            unset($previous[$node]);
        }

        return true;
    }
1120481
public function set($path, $value)
  {
    $old = null;
    if ( $nodes = explode('.', $path) ){
      $node = $this->data;

      for($i=0, $n=count($nodes)-1; $i<$n; $i++){
        if ( !isset($node->{$nodes[$i]}) && ($i != $n) ){
          $node->{$nodes[$i]} = new \stdClass;
        }
        
        $node = $node->{$nodes[$i]};
      }
      
      if ( isset($node->{$nodes[$i]}) ){
        $old = $node->{$nodes[$i]};
      }
      $node->{$nodes[$i]} = $value;
    }
    return $old;
  }
531711
static function setArrayValue(&$data,$name=null,$val=null) {   
        if(!is_array($data) || $name === NULL || $val === NULL) return(false);
        
        if(is_array($name))
            $path = $name;
        else
            $path = explode(".", $name);

        if(sizeof($path) < 1) return false;
        
        $ptr=&$data; 
        for($i=0;$i < sizeof($path); $i++) {            
            $attr = $path[$i];
            if(!isset($ptr[$attr])) return false;
            $ptr = &$ptr[$attr];
        }
        
        // kraj
        $ptr = $val;
        return true;
    }
813751
private function setFilePathCollection($path, array $data)
    {
        $key = \array_flip($this->filePathMapping)[$path];

        $this->filePathCollection[$key] = $data;
    }
882566
public static function set(array &$array, string $path, $value)
    {
        // Get segments from path
        $segments = explode('.', $path);

        // Loop through segments
        while (count($segments) > 1) {
            $segment = array_shift($segments);
            if (!isset($array[$segment]) || !is_array($array[$segment])) {
                $array[$segment] = [];
            }
            $array =& $array[$segment];
        }
        $array[array_shift($segments)] = $value;
    }
35339
public function offsetSet($path, $value)
	{
		if (is_null($path)) {
			$this->items[] = $value;
		} else {
			Arr::set($this->items, $this->keyFor($path), $value);
		}
	}
674417
public function pathSet( $path, $value )
	{
		$path = $this->createPath($path);
		if( $path[0] == 1 )
		{
			$this->offsetSet($path[1], $value);
		}
		else
		{
			$array = & $this->items;
			for( $i = 1, $len = $path[0]; $i <= $len; $i++ )
			{
				$key = $path[$i];
				if( $i == $len )
				{
					$array[$key] = $value;
				}
				else
				{
					if( !isset($array[$key]) || !is_array($array[$key]) )
					{
						$array[$key] = [];
					}

					$array = & $array[$key];
				}
			}
		}
		return $this;
	}
845921
public function set($path, $value)
    {
        $parts = explode('.', $path);
        switch (count($parts)) {
            case 2:
                $this->_data[$parts[0]][$parts[1]] = $value;
                break;
            case 1:
                $this->_data[$parts[0]] = $value;
                break;
            case 0:
                throw new RuntimeException('Path was empty.');
            default:
                throw new RuntimeException('Too many parts in path.');
        }
    }
1153927
public boolean set(String path, Object value) {
        jsonStore.clear();
        return JSONPath.set(jsonObject, checkPath(path), value);
    }
152646
public function setRaw($path, $value)
    {
        StructureHelper::setByPath($this->data, $path, $value, $this->separator);

        return $this;
    }
641526
public function prepend($path, $data, $separator = PHP_EOL)
    {
        if ($this->exists($path)) {
            return $this->put($path, $data.$separator.$this->get($path));
        }

        return $this->put($path, $data);
    }
1287242
public function setFilename($value, $overwrite = true, $separator = '_')
    {
        // recast to string if $value is array
        if (is_array($value)) {
            $value = implode($separator, $value);
        }

        // trim unneeded values
        $value = trim($value, $separator);

        // remove all spaces
        $value = preg_replace('/\s+/', $separator, $value);

        // if value is empty, stop here
        if (empty($value)) {
            return;
        }

        // decode value + lowercase the string
        $value = strtolower($this->decode($value));

        // urlize this part
        $value = Transliterator::urlize($value);

        // overwrite filename or add to filename using a prefix in between
        $this->filename = ($overwrite) ?
            $value : $this->filename . $separator . $value;
    }
1228461
public function put($path, $data)
    {
        if (false === $json = $this->runRequest($path, 'PUT', $data)) {
            return false;
        }

        return $this->decode($json);
    }
862731
public static function setByPath(&$data, $path, $value, $separator = '.', $storeType = 'array')
	{
		$nodes = array_values(array_filter(explode($separator, $path), 'strlen'));

		if (empty($nodes))
		{
			return false;
		}

		/**
		 * A closure as inner function to create data store.
		 *
		 * @param string $type
		 *
		 * @return  array
		 *
		 * @throws \InvalidArgumentException
		 */
		$createStore = function($type)
		{
			if (strtolower($type) == 'array')
			{
				return array();
			}

			if (class_exists($type))
			{
				return new $type;
			}

			throw new \InvalidArgumentException(sprintf('Type or class: %s not exists', $type));
		};

		$dataTmp = &$data;

		foreach ($nodes as $node)
		{
			if (is_object($dataTmp))
			{
				if (empty($dataTmp->$node))
				{
					$dataTmp->$node = $createStore($storeType);
				}

				$dataTmp = &$dataTmp->$node;
			}
			elseif (is_array($dataTmp))
			{
				if (empty($dataTmp[$node]))
				{
					$dataTmp[$node] = $createStore($storeType);
				}

				$dataTmp = &$dataTmp[$node];
			}
			else
			{
				// If a node is value but path is not go to the end, we replace this value as a new store.
				// Then next node can insert new value to this store.
				$dataTmp = &$createStore($storeType);
			}
		}

		// Now, path go to the end, means we get latest node, set value to this node.
		$dataTmp = $value;

		return true;
	}
1160722
public static function isSizeValue($value, $separator = ' x ')
    {
        /*
         * Not a string?
         * Nothing to do
         */
        if (!is_string($value)) {
            return false;
        }

        $pattern = self::getSizePattern($separator);

        return (bool)preg_match($pattern, $value);
    }
407907
static function pathSet(&$values, $pathParts, $value) {
        $r = &$values;
        $last = array_pop($pathParts);
        foreach ($pathParts as $part) {
            if (!isset($r[$part])) {
                $r[$part] = array();
            }
            $r = &$r[$part];
        }
        $r[$last] = $value;
    }