HTML::offsetSet()

Sets the attribute’s value.

Table of Contents
  1. Description
  2. Example

Description

HTML::offsetSet(mixed $key, mixed $value): void;

This method is a requirement to be able to implement the ArrayAccess interface and aims to make the object data modifiable using array access syntax. You won’t use this method directly, it will be executed automatically when you try to set an attribute’s value with array access syntax.

Example

$node = new HTML('<a name="test"></a>');

$node[0] = 'input';

echo $node; // Returns `'<input name="test"></input>'`

$node[1] = false;

echo $node; // Returns `'<input name="test">'`

$node['disabled'] = true;
$node['type'] = 'text';
$node['value'] = 'aaa"bbb';

echo $node; // Returns `'<input disabled name="test" type="text" value="aaa&quot;bbb">'`

HTML::offsetSet()

Sets the attribute’s value.