lithium\util\Set::insert PHP Method

insert() public static method

Inserts $data into an array as defined by $path.
public static insert ( mixed $list, mixed $path, array $data = [] ) : array
$list mixed Where to insert into.
$path mixed A dot-delimited string.
$data array Data to insert.
return array
    public static function insert($list, $path, $data = array())
    {
        if (!is_array($path)) {
            $path = explode('.', $path);
        }
        $_list =& $list;
        foreach ($path as $i => $key) {
            if (is_numeric($key) && (int) $key > 0 || $key === '0') {
                $key = (int) $key;
            }
            if ($i === count($path) - 1) {
                $_list[$key] = $data;
            } else {
                if (!isset($_list[$key])) {
                    $_list[$key] = array();
                }
                $_list =& $_list[$key];
            }
        }
        return $list;
    }

Usage Example

Beispiel #1
0
 /**
  * Write a value to the session.
  *
  * @param string $key Key of the item to be stored.
  * @param mixed $value The value to be stored.
  * @param array $options Options array. Not used for this adapter method.
  * @return closure Function returning boolean `true` on successful write, `false` otherwise.
  */
 public static function write($key, $value, array $options = array())
 {
     if (!static::isStarted() && !static::_start()) {
         throw new RuntimeException("Could not start session.");
     }
     $class = __CLASS__;
     return function ($self, $params) use($class) {
         return $class::overwrite($_SESSION, Set::insert($_SESSION, $params['key'], $params['value']));
     };
 }
All Usage Examples Of lithium\util\Set::insert