Resque\Helpers\Util::path PHP Method

path() public static method

Returns true if found and false if not.
public static path ( $array, $path, &$found, $delimiter = '.' ) : boolean
return boolean
    public static function path($array, $path, &$found, $delimiter = '.')
    {
        if (!is_array($array)) {
            return false;
        }
        if (is_array($path)) {
            $keys = $path;
        } else {
            if (array_key_exists($path, $array)) {
                $found = $array[$path];
                // No need to do extra processing
                return true;
            }
            $keys = explode($delimiter, trim($path, "{$delimiter} "));
        }
        do {
            $key = array_shift($keys);
            if (ctype_digit($key)) {
                $key = (int) $key;
            }
            if (isset($array[$key])) {
                if ($keys) {
                    if (is_array($array[$key])) {
                        $array = $array[$key];
                    } else {
                        break;
                    }
                } else {
                    $found = $array[$key];
                    return true;
                }
            } else {
                break;
            }
        } while ($keys);
        // Unable to find the value requested
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Gets Resque config variable
  *
  * @param  string  $key     The key to search for (optional)
  * @param  mixed   $default If key not found returns this (optional)
  * @return mixed
  */
 public static function getConfig($key = null, $default = null)
 {
     if (!is_null($key)) {
         if (false !== Util::path(static::$config, $key, $found)) {
             return $found;
         } else {
             return $default;
         }
     }
     return static::$config;
 }
All Usage Examples Of Resque\Helpers\Util::path