Esempio n. 1
0
 /**
  * Find Key value in collection, returns default on failure
  *
  * @param null $key Key to be searched
  * @param bool $default Default value to return on failure
  * @return array|bool|mixed
  */
 public function get($key = null, $default = false)
 {
     $hash = md5($key);
     // internal cache check
     if (isset($this->_cache[$hash])) {
         return $this->_cache[$hash];
     }
     if (is_null($key)) {
         $this->_cache[$hash] = $this->collection;
         return $this->collection;
     } elseif (strpos($key, '.') !== false) {
         $response = dotGet($key, $this->collection, $default);
         $this->_cache[$hash] = $response;
         return $response;
     } elseif (array_key_exists($key, $this->collection)) {
         $this->_cache[$hash] = $this->collection[$key];
         return $this->collection[$key];
     } else {
         $response = searchArrayByKey($this->collection, $key, $default);
         $this->_cache[$hash] = $response;
         return $response;
     }
 }
Esempio n. 2
0
/**
 * return array with same keyvalue
 */
function searchArrayByKey($array, $key, $value)
{
    $results = array();
    if (is_array($array)) {
        if (isset($array[$key]) && $array[$key] == $value) {
            $results[] = $array;
        }
        foreach ($array as $subarray) {
            $results = array_merge($results, searchArrayByKey($subarray, $key, $value));
        }
    }
    return $results;
}