Supported Versions: PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8
Searches the array for a given value and returns the first corresponding key if successful
<?php array_search(mixed $needle, array $haystack, bool $strict = false): int|string|false
<?php public function search($value, $strict = false)
{
if (! $this->useAsCallable($value)) {
return array_search($value, $this->items, $strict);
}
foreach ($this->items as $key => $item) {
<?php return (int) $choice[1];
} else {
return array_search(
select('Which command would you like to run?', $commandNames),
$commandNames
);
}
}
}
<?php $morphMap = Relation::morphMap();
if (! empty($morphMap) && in_array(static::class, $morphMap)) {
return array_search(static::class, $morphMap, true);
}
if (static::class === Pivot::class) {
<?php $morphMap = Relation::morphMap();
if (! empty($morphMap) && in_array($model, $morphMap)) {
$model = array_search($model, $morphMap, true);
}
return $this->where($relation->getMorphType(), $model, null, $boolean);
<?php $morphMap = Relation::morphMap();
if (! empty($morphMap) && in_array($model, $morphMap)) {
$model = array_search($model, $morphMap, true);
}
return $this->whereNot($relation->getMorphType(), '<=>', $model, $boolean);
<?php })->flatten(1)
)
->sortBy(function ($data, $key) {
$index = array_search($key, ['Environment', 'Cache', 'Drivers']);
return $index === false ? 99 : $index;
})
<?php public function prependMiddleware($middleware)
{
if (array_search($middleware, $this->middleware) === false) {
array_unshift($this->middleware, $middleware);
}
<?php public function pushMiddleware($middleware)
{
if (array_search($middleware, $this->middleware) === false) {
$this->middleware[] = $middleware;
}
<?php throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
}
if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
array_unshift($this->middlewareGroups[$group], $middleware);
}
<?php throw new InvalidArgumentException("The [{$group}] middleware group has not been defined.");
}
if (array_search($middleware, $this->middlewareGroups[$group]) === false) {
$this->middlewareGroups[$group][] = $middleware;
}
<?php public function parentOfParameter($parameter)
{
$key = array_search($parameter, array_keys($this->parameters));
if ($key === 0 || $key === false) {
return;
<?php protected function priorityMapIndex($priorityMap, $middleware)
{
foreach ($this->middlewareNames($middleware) as $name) {
$priorityIndex = array_search($name, $priorityMap);
if ($priorityIndex !== false) {
return $priorityIndex;
<?php $this->test->fail('Output does not contain "'.Arr::first($this->test->expectedOutputSubstrings).'".');
}
if ($output = array_search(true, $this->test->unexpectedOutput)) {
$this->test->fail('Output "'.$output.'" was printed.');
}
<?php $this->test->fail('Output "'.$output.'" was printed.');
}
if ($output = array_search(true, $this->test->unexpectedOutputSubstrings)) {
$this->test->fail('Output "'.$output.'" was printed.');
}
}
<?php public function addExtension($extension)
{
if (($index = array_search($extension, $this->extensions)) !== false) {
unset($this->extensions[$index]);
}