fonction in_array () de PHP
PHP complet Tableau de référence
Exemples
Recherche la valeur du tableau "Glenn", et sort du texte:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
if (in_array("Glenn", $people))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
if (in_array("Glenn", $people))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>
Exécution instance »
Définition et utilisation
fonction in_array () pour spécifier la valeur de l'existence du réseau de recherche.
Remarque: Si leparamètre de recherche est une chaîne et le paramètre de type est réglé sur TRUE, la recherche est sensible à la casse.
grammaire
in_array( search,array,type )
参数 | 描述 |
---|---|
search | 必需。规定要在数组搜索的值。 |
array | 必需。规定要搜索的数组。 |
type | 可选。如果该参数设置为 TRUE,则 in_array() 函数检查搜索的数据与数组的值的类型是否相同。 |
détails techniques
Retours: | Si vous trouvez la valeur dans le tableau, il retourne TRUE, sinon retourne FALSE. |
---|---|
PHP version: | 4+ |
Mise à jour Connexion | Depuis PHP 4.2 partir, le paramètre de recherche peut être un tableau. |
D'autres exemples
exemple 1
Utilisez tous les paramètres:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland", 23);
if (in_array("23", $people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array("Glenn",$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array(23,$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland", 23);
if (in_array("23", $people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array("Glenn",$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
if (in_array(23,$people, TRUE))
{
echo "Match found<br>";
}
else
{
echo "Match not found<br>";
}
?>
Exécution instance »
PHP complet Tableau de référence