1818
1919/**
2020 * Trait providing methods for accessing elements in ArrayView object.
21+ *
2122 * The trait implements methods for accessing, retrieving, setting,
2223 * and unsetting elements in the ArrayView object.
2324 *
@@ -29,6 +30,27 @@ trait ArrayViewAccessTrait
2930 /**
3031 * Check if the specified offset exists in the ArrayView object.
3132 *
33+ * ```php
34+ * $source = [1, 2, 3, 4, 5];
35+ * $view = ArrayView::toView($source);
36+ *
37+ * isset($view[0]); // true
38+ * isset($view[-1]); // true
39+ * isset($view[10]); // false
40+ *
41+ * isset($view[new SliceSelector('::2')]); // true
42+ * isset($view[new IndexListSelector([0, 2, 4])]); // true
43+ * isset($view[new IndexListSelector([0, 2, 10])]); // false
44+ * isset($view[new MaskSelector([true, true, false, false, true])]); // true
45+ * isset($view[new MaskSelector([true, true, false, false, true, true])]); // false
46+ *
47+ * isset($view['::2']); // true
48+ * isset($view[[0, 2, 4]]); // true
49+ * isset($view[[0, 2, 10]]); // false
50+ * isset($view[[true, true, false, false, true]]); // true
51+ * isset($view[[true, true, false, false, true, true]]); // false
52+ * ```
53+ *
3254 * @param numeric|S $offset The offset to check.
3355 *
3456 * @return bool
@@ -51,7 +73,23 @@ public function offsetExists($offset): bool
5173 /**
5274 * Get the value at the specified offset in the ArrayView object.
5375 *
54- * @param numeric|S $offset The offset to get the value from.
76+ * ```php
77+ * $source = [1, 2, 3, 4, 5];
78+ * $view = ArrayView::toView($source);
79+ *
80+ * $view[0]; // 1
81+ * $view[-1]; // 5
82+ *
83+ * $view[new SliceSelector('::2')]; // [1, 3, 5]
84+ * $view[new IndexListSelector([0, 2, 4])]; // [1, 3, 5]
85+ * $view[new MaskSelector([true, true, false, false, true])]; // [1, 2, 5]
86+ *
87+ * $view['::2']; // [1, 3, 5]
88+ * $view[[0, 2, 4]]; // [1, 3, 5]
89+ * $view[[true, true, false, false, true]]; // [1, 3, 5]
90+ * ```
91+ *
92+ * @param numeric|S $offset The offset to get the value at.
5593 *
5694 * @return T|array<T> The value at the specified offset.
5795 *
@@ -76,6 +114,40 @@ public function offsetGet($offset)
76114 /**
77115 * Set the value at the specified offset in the ArrayView object.
78116 *
117+ * ```php
118+ * $source = [1, 2, 3, 4, 5];
119+ * $view = ArrayView::toView($source);
120+ *
121+ * $view[0] = 11;
122+ * $view[-1] = 55;
123+ *
124+ * $source; // [11, 2, 3, 4, 55]
125+ *
126+ * $source = [1, 2, 3, 4, 5];
127+ * $view = ArrayView::toView($source);
128+ *
129+ * $view[new SliceSelector('::2')] = [11, 33, 55];
130+ * $source; // [11, 2, 33, 4, 55]
131+ *
132+ * $view[new IndexListSelector([1, 3])] = [22, 44];
133+ * $source; // [11, 22, 33, 44, 55]
134+ *
135+ * $view[new MaskSelector([true, false, false, false, true])] = [111, 555];
136+ * $source; // [111, 22, 33, 44, 555]
137+ *
138+ * $source = [1, 2, 3, 4, 5];
139+ * $view = ArrayView::toView($source);
140+ *
141+ * $view['::2'] = [11, 33, 55];
142+ * $source; // [11, 2, 33, 4, 55]
143+ *
144+ * $view[[1, 3]] = [22, 44];
145+ * $source; // [11, 22, 33, 44, 55]
146+ *
147+ * $view[[true, false, false, false, true]] = [111, 555];
148+ * $source; // [111, 22, 33, 44, 555]
149+ * ```
150+ *
79151 * @param numeric|S $offset The offset to set the value at.
80152 * @param T|array<T>|ArrayViewInterface<T> $value The value to set.
81153 *
0 commit comments