CKTIS / PHP
in_array()
Cerca tra i valori dell’array ignorando le chiavi.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
in_array(mixed $needle, array $haystack, bool $strict = false): boolCerca tra i valori dell’array ignorando le chiavi. Il confronto debole predefinito equipara 2 a "2". Con strict a true conta anche il tipo. Il booleano restituito non fornisce la chiave.
Firma
in_array(mixed $needle, array $haystack, bool $strict = false): bool
Output dell’esempio
[true,false,true,false]
Esempi
<?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)]);
Risultato
[true,false,true,false]