JBZoo\Utils\Arr::key PHP Method

key() public static method

Check is key exists
public static key ( string $key, mixed $array, boolean $returnValue = false ) : mixed
$key string
$array mixed
$returnValue boolean
return mixed
    public static function key($key, $array, $returnValue = false)
    {
        $isExists = array_key_exists((string) $key, (array) $array);
        if ($returnValue) {
            if ($isExists) {
                return $array[$key];
            }
            return null;
        }
        return $isExists;
    }

Usage Example

Example #1
0
File: Radio.php Project: JBZoo/Html
 /**
  * Check selected option in list.
  *
  * @param array $options
  * @param string $selectedVal
  * @return array
  */
 protected function _checkSelected(array $options, $selectedVal)
 {
     if (!empty($selectedVal) && !Arr::key($selectedVal, $options)) {
         $selectedVal = self::KEY_NO_EXITS_VAL;
         $options = array_merge(array(self::KEY_NO_EXITS_VAL => $this->_translate('No exits')), $options);
     }
     return array($options, $selectedVal);
 }
All Usage Examples Of JBZoo\Utils\Arr::key