Files
doc-fr/reference/array/functions/in-array.xml
Jean-Sébastien Goupil dcbd76b0cc sync with EN
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@222717 c90b9560-bf6c-de11-be94-00142212c4b1
2006-11-03 12:03:58 +00:00

149 lines
3.8 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.26 $ -->
<!-- EN-Revision: 1.13 Maintainer: dams Status: ready -->
<!-- Reviewed: no -->
<refentry id="function.in-array">
<refnamediv>
<refname>in_array</refname>
<refpurpose>Indique si une valeur appartient à un tableau</refpurpose>
</refnamediv>
<refsect1>
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>in_array</methodname>
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
<methodparam><type>array</type><parameter>haystack</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>strict</parameter></methodparam>
</methodsynopsis>
<para>
<function>in_array</function> recherche <parameter>needle</parameter> dans
<parameter>haystack</parameter> et retourne &true;
s'il s'y trouve, ou &false; sinon.
</para>
<para>
Le troisième paramètre <parameter>strict</parameter> est
optionnel. S'il vaut &true; alors <function>in_array</function>
vérifiera aussi que le <link linkend="language.types">types</link>
du paramètre <parameter>needle</parameter>
correspond au type de la valeur trouvée dans <parameter>haystack</parameter>.
</para>
<note>
<para>
Si <parameter>needle</parameter> est une chaîne, la comparaison
est faite en tenant compte de la casse.
</para>
</note>
<note>
<para>
Dans les versions antérieure à 4.2.0, <parameter>needle</parameter> ne pouvait
pas être un tableau.
</para>
</note>
<para>
<example>
<title>Exemple avec <function>in_array</function></title>
<programlisting role="php">
<![CDATA[
<?php
$os = array ("Mac", "NT", "Irix", "Linux");
if (in_array ("Linux", $os)) {
print "Trouvé Linux";
}
if (in_array ("mac", $os)) {
print "Trouvé mac";
}
?>
]]>
</programlisting>
<para>
La seconde condition échoue, car <function>in_array</function>
est sensible à la casse. Le script retourne :
</para>
<screen role="php">
<![CDATA[
Trouvé Linux
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Exemple avec <function>in_array</function> et le mode strict</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, TRUE))
echo "'12.4' a été trouvé avec recherche stricte\n";
if (in_array(1.13, $a, TRUE))
echo "1.13 a été trouvé avec recherche stricte\n";
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
1.13 a été trouvé avec recherche stricte
]]>
</screen>
</example>
</para>
<para>
<example>
<title>
Exemple avec <function>in_array</function> et deux tableaux en paramètres
</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array ('p', 'h'), $a))
echo "'ph' a été trouvé\n";
if (in_array(array ('f', 'i'), $a))
echo "'fi' a été trouvé\n";
if (in_array('o', $a))
echo "'o' a été trouvé\n";
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
'ph' a été trouvé
'o' a été trouvé
]]>
</screen>
</example>
</para>
<para>
Voir aussi
<function>array_search</function>,
<function>array_key_exists</function> et
<function>isset</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->