in_array

in_array -- Indique si une valeur appartient à un tableau

Description

boolean in_array ( mixed needle, array haystack [, boolean strict])

in_array( ) recherche needle dans haystack et retourne TRUE s'il s 'y trouve , ou FALSE sinon .

Le troisième paramètre strict est optionnel . S' il vaut TRUE alors in_array( ) vérifiera aussi que le types du paramètre needle correspond à la valeur trouvée dans haystack .

Exemple 1 . Exemple avec in_array( )

 
?php

 
$os

 
=

 
array(

 
"Mac"

 
,

 
"NT"

 
,

 
"Irix"

 
,

 
"Linux")

 
;

 
if

 
(in_array("Irix"

 
,

 
$os)

 
)

 
print

 
"Irix

 
trouve"

 
;

 
?





Exemple 2 . in_array( ) avec le paramètre strict

 
 ?php

 
$a

 
=

 
array(

 
'1.10'

 
,

 
12.4

 
,

 
1.13)

 
;

 
if

 
(in_array('12.4'

 
,

 
$a

 
,

 
  
   
TRUE

  

 

 
)

 
)

 
echo

 
"'12.4

 
'

 
trouvé

 
avec

 
une

 
recherche

 
stricte\n"

 
;

 
if

 
(in_array(1.13

 
,

 
$a

 
,

 
  
   
TRUE

  

 

 
)

 
)

 
echo

 
"1.13

 
trouvé

 
avec

 
une

 
recherche

 
stricte\n"

 
;

 
?





L ' affichage sera :

 
1.13

 
trouvé

 
avec

 
une

 
recherche

 
stricte



Note : in_array() a été ajoutée en PHP 4.0.

Voir aussi array_search( ) .