diff --git a/src/Ary.php b/src/Ary.php index 7fba035..f4512bb 100644 --- a/src/Ary.php +++ b/src/Ary.php @@ -88,10 +88,8 @@ class Ary extends \ArrayObject implements \ArrayAccess, \Countable, \IteratorAgg public function &get($key, $default = null) { if ($this->offsetExists($key)) { - - return $this[$key]; + return $this->getArrayCopy()[$key]; } - return $default; } @@ -195,4 +193,18 @@ class Ary extends \ArrayObject implements \ArrayAccess, \Countable, \IteratorAgg return (object)$this->all(); } + /** + * Search the ary for a given value and return the corresponding key if successful. + * + * @param mixed $value + * @param bool $strict + * @return mixed + */ + public function search($value, $strict = false) + { + return array_search($value, $this->getArrayCopy(), $strict); + + } + + } \ No newline at end of file diff --git a/test/Test.php b/test/Test.php index 2d87e1f..27c2f1d 100644 --- a/test/Test.php +++ b/test/Test.php @@ -6,9 +6,10 @@ * Date: 2015/10/15 * Time: 11:12 AM */ -use salarmehr\ary; -require '..\src\Ary.php'; +use \Salarmehr\Ary; + +require __DIR__ . '/../src/Ary.php'; class Test extends PHPUnit_Framework_TestCase {