本文整理汇总了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);
}
示例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);
}
}
示例3: array_include
function array_include(&$array, $item)
{
if (!array_contains($array, $item)) {
$array[] = $item;
}
return $array;
}
示例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;
}
示例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);
}
}
}
示例6: array_erase
function array_erase(&$array, $item)
{
if (!array_contains($array, $item)) {
return $array;
}
array_splice($array, $index, 1);
return $array;
}
示例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'));
}
示例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;
}
示例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");
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}