CKTIS / PHP
in_array()
Procura nos valores do array sem examinar as chaves.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
in_array(mixed $needle, array $haystack, bool $strict = false): boolProcura nos valores do array sem examinar as chaves. A comparação flexível predefinida equipara 2 a "2". Com strict a true também conta o tipo. O resultado booleano não indica a chave.
Assinatura
in_array(mixed $needle, array $haystack, bool $strict = false): bool
Saída do exemplo
[true,false,true,false]
Exemplos
<?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)]);
Resultado
[true,false,true,false]