CKTIS / PHP
in_array()
Check whether an array contains a value without searching its keys.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
in_array(mixed $needle, array $haystack, bool $strict = false): boolCheck whether an array contains a value without searching its keys. By default loose equality can match integer 2 with the string "2". Set strict to true when type is significant. The boolean result does not reveal the matched key.
Signature
in_array(mixed $needle, array $haystack, bool $strict = false): bool
Example output
[true,false,true,false]
Examples
<?php
$ids = ["student"=>"2"];
echo json_encode([in_array(2,$ids),in_array(2,$ids,true),in_array("2",$ids,true),in_array("student",$ids,true)]);
Result
[true,false,true,false]