lithium\util\Set::remove PHP Method

remove() public static method

Removes an element from an array as defined by $path.
public static remove ( mixed $list, mixed $path = null ) : array
$list mixed From where to remove.
$path mixed A dot-delimited string.
return array Array with `$path` removed from its value.
    public static function remove($list, $path = null)
    {
        if (empty($path)) {
            return $list;
        }
        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) {
                unset($_list[$key]);
            } else {
                if (!isset($_list[$key])) {
                    return $list;
                }
                $_list =& $_list[$key];
            }
        }
        return $list;
    }

Usage Example

Beispiel #1
0
 /**
  * Delete value from the session
  *
  * @param string $key The key to be deleted
  * @param array $options Options array. Not used for this adapter method.
  * @return closure Function returning boolean `true` if the key no longer exists
  *         in the session, `false` otherwise
  */
 public static function delete($key, array $options = array())
 {
     if (!static::isStarted() && !static::_start()) {
         throw new RuntimeException("Could not start session.");
     }
     $class = __CLASS__;
     return function ($self, $params) use($class) {
         $key = $params['key'];
         $class::overwrite($_SESSION, Set::remove($_SESSION, $key));
         return !Set::check($_SESSION, $key);
     };
 }
All Usage Examples Of lithium\util\Set::remove