diff --git a/src/core/ArrayObject.php b/src/core/ArrayObject.php index 19680f11..ccc0abce 100644 --- a/src/core/ArrayObject.php +++ b/src/core/ArrayObject.php @@ -651,6 +651,17 @@ public function usort(callable $value_compare_func): self return $this; } + public function isAssoc(): bool + { + foreach (array_keys($this->array) as $key) { + if (is_string($key)) { + return true; + } + } + + return false; + } + /** * @param mixed $value * @return ArrayObject|mixed|StringObject diff --git a/tests/unit/ArrayObjectTest.php b/tests/unit/ArrayObjectTest.php index 68a9bea6..ed5848e1 100644 --- a/tests/unit/ArrayObjectTest.php +++ b/tests/unit/ArrayObjectTest.php @@ -581,4 +581,12 @@ public function testLastKey() { $this->assertEquals($this->data_4->lastKey(), 'c'); } + + public function testIsAssoc() + { + $this->assertFalse($this->data->isAssoc()); + $this->assertFalse($this->data_2->isAssoc()); + $this->assertTrue($this->data_3->isAssoc()); + $this->assertTrue($this->data_4->isAssoc()); + } }