- adding search method

- resoling an issue
This commit is contained in:
Reza
2015-10-18 12:20:55 +03:30
parent 18a44faad0
commit 28369b2aef
2 changed files with 18 additions and 5 deletions

View File

@ -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);
}
}

View File

@ -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
{