State::set()

Sets a state or states.

Table of Contents
  1. Description
  2. Example

Description

State::set(array $keys, mixed $value): void;
State::set(array $values): void;
State::set(string $key, mixed $value): void;

This method sets a state or states. If a state already exists, this method will override that state or states. It is possible to use dot notation access if you want to set the states recursively. To keep the dot character as part of the key, prefix it with a \.

Example

State::set('foo', 1); // State is now `['foo' => 1]`
State::set('foo.bar', 1); // State is now `['foo' => ['bar' => 1]]`
State::set('foo\.bar', 1); // State is now `['foo' => ['bar' => 1], 'foo.bar' => 1]`
State::set(['bar', 'foo'], 1); // State is now `['bar' => 1, 'foo' => 1, 'foo.bar' => 1]`
State::set(['bar' => 1, 'foo' => 2]); // State is now `['bar' => 1, 'foo' => 2, 'foo.bar' => 1]`
State::set(['bar' => 1, 'foo.bar' => 2]); // State is now `['bar' => 1, 'foo' => ['bar' => 2], 'foo.bar' => 1]`

State::set()

Sets a state or states.