Helper::elementFinder PHP Method

elementFinder() public static method

Find an element in a nested hasharray $haystack with a string $needle separated by $delimiter
public static elementFinder ( $needle, array $haystack, string $delimiter = '.' ) : null
$needle
$haystack array
$delimiter string
return null
    public static function elementFinder($needle, $haystack, $delimiter = '.')
    {
        $break = strpos($needle, $delimiter);
        $key = $break === false ? $needle : substr($needle, 0, $break);
        if (isset($haystack[$key])) {
            if ($key == $needle) {
                return $haystack[$key];
            }
            return static::elementFinder(substr($needle, $break + 1), $haystack[$key]);
        } else {
            return null;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Set portal config.
  *
  * @throws InvalidArgumentException
  */
 protected function setConfig()
 {
     $config = $this->yii->params['portal'];
     if (!$config) {
         throw new InvalidArgumentException('Missing portal configuration for ' . __CLASS__);
     }
     foreach (static::$required_config_keys as $k) {
         if (Helper::elementFinder($k, $config) === null) {
             throw new InvalidArgumentException('Missing required config parameter for ' . __CLASS__);
         }
     }
     $this->config = $config;
 }
All Usage Examples Of Helper::elementFinder