From 6ddc62460c1ee6d682c4a58b866b09d7f65bca04 Mon Sep 17 00:00:00 2001 From: Reza Date: Mon, 9 Nov 2015 19:57:05 +0330 Subject: [PATCH] Adding ary method --- src/Ary.php | 5 +++++ test/Test.php | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Ary.php b/src/Ary.php index d3d751c..476109a 100644 --- a/src/Ary.php +++ b/src/Ary.php @@ -282,4 +282,9 @@ class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable { return array_search($value, $this->items, $strict); } + + public function ary($item) + { + return new ary($this->get($item)); + } } \ No newline at end of file diff --git a/test/Test.php b/test/Test.php index 6ad9a6c..f79145b 100644 --- a/test/Test.php +++ b/test/Test.php @@ -127,6 +127,17 @@ class Test extends PHPUnit_Framework_TestCase $this->assertEquals(json_encode(new Ary($original)), json_encode((array)$original)); } + /** + * @dataProvider various + */ + public function ary() + { + $test = ['x' => ['xx' => 'xxx']]; + $ary = new Ary($test); + $this->assertEquals(ary($test)->x['xx'], $ary->ary('x')->xx); + $this->assertEquals(ary(ary($test)->x['xx']), $ary->ary('x')->ary('xx')); + } + // public function testOffsetExists() // { // $parameters = array(7,8,9,4);