Skip to content

Commit ecbbdfc

Browse files
doublemczdg
authored andcommitted
ArrayList: added prepend()
1 parent 649a129 commit ecbbdfc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Utils/ArrayList.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,15 @@ public function offsetUnset($index)
9999
array_splice($this->list, (int) $index, 1);
100100
}
101101

102+
103+
/**
104+
* Prepends a item.
105+
* @param mixed
106+
* @return void
107+
*/
108+
public function prepend($value)
109+
{
110+
array_unshift($this->list, $value);
111+
}
112+
102113
}

tests/Utils/ArrayList.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,7 @@ test(function () {
7171
Assert::same([
7272
$mary,
7373
], iterator_to_array($list));
74+
75+
$list->prepend('First');
76+
Assert::same('First', $list[0], 'Value "First" should be on the start of the array');
7477
});

0 commit comments

Comments
 (0)