当前位置: 首页>>代码示例>>PHP>>正文


PHP array_contains函数代码示例

本文整理汇总了PHP中array_contains函数的典型用法代码示例。如果您正苦于以下问题:PHP array_contains函数的具体用法?PHP array_contains怎么用?PHP array_contains使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了array_contains函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ask

 /**
  * @param $string
  * @param bool $default
  *
  * @return bool
  */
 public function ask($string, $default = null)
 {
     if ($default === true) {
         $suffix = 'Y/n';
     } else {
         if ($default === false) {
             $suffix = 'y/N';
         } else {
             $suffix = 'y/n';
         }
     }
     $this->output->write("<question>{$string}</question> [<yellow>{$suffix}</yellow>]: ");
     $input = $this->input->readLine();
     if (array_contains(['yes', 'y'], $input)) {
         return true;
     }
     if (array_contains(['no', 'n'], $input)) {
         return false;
     }
     if (empty($input)) {
         if ($default === true) {
             return true;
         }
         if ($default === false) {
             return false;
         }
     }
     return $this->ask($string, $default);
 }
开发者ID:weew,项目名称:console,代码行数:35,代码来源:PromptHelper.php

示例2: __construct

 public function __construct($request_path, $request_params, $request_method, $return_type)
 {
     $function = array('class_name' => __NAMESPACE__, 'method_name' => __METHOD__);
     //validating the return type and set default if not found
     if (array_contains($return_type, Constants::get('allowed_return_types') == false)) {
         $return_type = Constants::get('default_return_type');
     } else {
         $this->return_type = set_default($return_type, Constants::get('allowed_return_types'));
     }
     //validate if request path is valid else throw error
     if (is_ready($request_path) == false) {
         $error = Tool::prepare('Request path is invalid, unable to process routing request.', 'Request path is null, verify that index router has parsed the information correctly.', __LINE__, $this->return_type, Constants::get('default_error_code'));
         Tool::error($function, $error, false);
     } else {
         enforce_inputs(array($request_path, 'array', null, null, false), $this->return_type);
         $this->original_path = $request_path;
         $this->request_path = $request_path;
     }
     //validate if request method is valid, else set as default (post takes precendence if both are used)
     $this->request_method = set_default($request_method, Constants::get('default_http_method'));
     $allowed_http_methods = Constants::get('allowed_http_methods');
     if (array_contains($request_method, $allowed_http_methods, false) == false) {
         $request_method = Constants::get('default_http_method');
     }
     $this->request_method = strtolower($request_method);
     //add post params to class if exist
     $this->request_params = $request_params;
     //normalise request_path
     if (is_ready(end($this->request_path)) == false) {
         array_pop($this->request_path);
     }
 }
开发者ID:kennho,项目名称:router,代码行数:32,代码来源:route.php

示例3: array_include

function array_include(&$array, $item)
{
    if (!array_contains($array, $item)) {
        $array[] = $item;
    }
    return $array;
}
开发者ID:subtleGradient,项目名称:packager,代码行数:7,代码来源:array.php

示例4: addMapping

 /**
  * @param string $contentType
  * @param string $dataClass
  *
  * @throws InvalidDataClassException
  */
 public function addMapping($contentType, $dataClass)
 {
     if (!class_exists($dataClass) || !array_contains(class_implements($dataClass), IHttpData::class)) {
         throw new InvalidDataClassException(s('Class "%s" must implement the "%s" interface.', $dataClass, IHttpData::class));
     }
     $this->mappings[$contentType] = $dataClass;
 }
开发者ID:weew,项目名称:http,代码行数:13,代码来源:ContentTypeDataMatcher.php

示例5: extractSpecialHeaders

 /**
  * @param IHttpHeaders $headers
  * @param array $server
  * @param array $specialHeaders
  */
 public function extractSpecialHeaders(IHttpHeaders $headers, array $server, array $specialHeaders)
 {
     foreach ($server as $header => $value) {
         if (array_contains($specialHeaders, $header)) {
             $headers->add($this->formatHeader($header), $value);
         }
     }
 }
开发者ID:weew,项目名称:http,代码行数:13,代码来源:ReceivedHeadersParser.php

示例6: array_erase

function array_erase(&$array, $item)
{
    if (!array_contains($array, $item)) {
        return $array;
    }
    array_splice($array, $index, 1);
    return $array;
}
开发者ID:pizarrodiego,项目名称:packager,代码行数:8,代码来源:array.php

示例7: testArrayContains

 public function testArrayContains()
 {
     $arrayA = array('foo', 'bar', 'baz');
     $arrayB = array('foo', 'bar');
     $arrayC = array('foo', 'apple');
     $this->assertTrue(array_contains($arrayA, $arrayB));
     $this->assertFalse(array_contains($arrayA, $arrayC));
     $this->assertTrue(array_contains($arrayA, 'bar'));
 }
开发者ID:howlowck,项目名称:support,代码行数:9,代码来源:HelpersTest.php

示例8: occurrence

/**
 * check times of occurrence of $target in $universal_set
 * $target: array of string
 * $universal_set: array of array of string
 */
function occurrence($target, $universal_set)
{
    $count = 0;
    foreach ($universal_set as $keywords_arr) {
        if (array_contains($keywords_arr, $target)) {
            $count++;
        }
    }
    return $count;
}
开发者ID:AndreaBuffa,项目名称:recsys-nju,代码行数:15,代码来源:aggregate_utility.inc.php

示例9: getLayout

 public static function getLayout($layout)
 {
     if (array_contains($this->layouts, $layout)) {
         return "Layout not found!";
     }
     foreach (self::$layoutFolders as $folder) {
         if (Files::exists($folder . "/" . $layout . ".php")) {
             return Files::readString($folder . "/" . $layout . ".php");
         }
     }
 }
开发者ID:ArkayCZ,项目名称:NexusFramework,代码行数:11,代码来源:LayoutManager.php

示例10: parseMethod

 /**
  * @param array $server
  *
  * @return mixed
  */
 public function parseMethod(array $server)
 {
     $method = array_get($server, 'REQUEST_METHOD');
     if (array_has($server, '_method')) {
         $_method = strtoupper(array_get($server, '_method'));
         if (array_contains(HttpRequestMethod::getMethods(), $_method)) {
             return $_method;
         }
     }
     return $method;
 }
开发者ID:weew,项目名称:http,代码行数:16,代码来源:ReceivedRequestParser.php

示例11: check

 /**
  * @param $value
  * @param IValidationData $data
  *
  * @return bool
  */
 public function check($value, IValidationData $data = null)
 {
     if (is_array($value)) {
         foreach ($value as $item) {
             if (array_contains($this->forbidden, $item)) {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
开发者ID:weew,项目名称:validator,代码行数:18,代码来源:ForbiddenSubsetConstraint.php

示例12: resolve

 /**
  * @param $name
  * @param $repositoryClass
  *
  * @return $this
  * @throws InvalidRepositoryClassException
  * @throws RepositoryClassNotFoundException
  */
 public function resolve($name, $repositoryClass)
 {
     if (!class_exists($repositoryClass)) {
         throw new RepositoryClassNotFoundException(s('Class "%s" not found.', $repositoryClass));
     }
     if (!array_contains(class_implements($repositoryClass), ObjectRepository::class)) {
         throw new InvalidRepositoryClassException(s('Class "%s" must implement interface "%s".', $repositoryClass, ObjectRepository::class));
     }
     $this->router->addResolver($name, function ($parameter, IContainer $container) use($repositoryClass) {
         $repository = $container->get($repositoryClass);
         return $repository->find($parameter);
     });
     return $this;
 }
开发者ID:weew,项目名称:router-entities-resolver,代码行数:22,代码来源:EntitiesResolver.php

示例13: getValues

 /**
  * @param mixed $data
  * @param array $keys
  *
  * @return array
  */
 protected function getValues($data, array $keys)
 {
     $key = array_shift($keys);
     if (array_contains(['', null], $key)) {
         return [];
     }
     if ($key === ValidationToken::WILDCARD_VALUES) {
         $values = $this->getWildcardValues($data, $keys);
     } else {
         if ($key === ValidationToken::WILDCARD_KEYS) {
             $values = $this->getWildcardKeys($data, $keys);
         } else {
             $values = $this->getRegularValues($data, $key, $keys);
         }
     }
     return $values;
 }
开发者ID:weew,项目名称:validator,代码行数:23,代码来源:ValidationData.php

示例14: product_is_wishlisted

function product_is_wishlisted($retailer, $pid)
{
    $product = product_get_raw($retailer, $pid);
    $lists = lists_get_for_user();
    $list_ids = array();
    foreach ($lists as $list) {
        $list_ids[] = $list['id'];
    }
    $list_ids[] = 'def_' . current_user();
    if ($product) {
        $lists = @$product['lists'] ?: array();
        foreach ($list_ids as $list_id) {
            if (array_contains($lists, $list_id)) {
                return true;
            }
        }
    }
    return false;
}
开发者ID:Ometria,项目名称:retail_week_hackathon_2014,代码行数:19,代码来源:models.php

示例15: ifr_add_class

 /**
  * @param Zend_Form_Element|Zend_Form|array $target
  * @param string                            $class
  */
 function ifr_add_class(&$target, $class)
 {
     if (!is_array($target)) {
         $attrib = $target->getAttrib('class');
         $classes = explode(' ', $attrib);
     } else {
         $attrib = array_key_exists('class', $target) ? $target['class'] : '';
         $classes = is_array($attrib) ? $attrib : explode(' ', $attrib);
     }
     $classes = array_filter($classes);
     if (!array_contains($classes, $class)) {
         if (!is_array($target)) {
             if (!empty($attrib)) {
                 $attrib .= ' ';
             }
             $target->setAttrib('class', $attrib . $class);
         } else {
             $classes[] = $class;
             $target['class'] = implode(' ', $classes);
         }
     }
 }
开发者ID:tapiau,项目名称:muyo,代码行数:26,代码来源:zend.php


注:本文中的array_contains函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。