mirror of
https://github.com/php/doc-fr.git
synced 2026-03-25 15:42:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@114911 c90b9560-bf6c-de11-be94-00142212c4b1
145 lines
4.0 KiB
XML
145 lines
4.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- splitted from ./fr/functions/array.xml, last change in rev 1.30 -->
|
|
<!-- last change to 'in-array' in en/ tree in rev 1.56 -->
|
|
<refentry id="function.in-array">
|
|
<refnamediv>
|
|
<refname>in_array</refname>
|
|
<refpurpose>
|
|
Indique si une valeur appartient à un tableau
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<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 types du paramètre <parameter>needle</parameter>
|
|
correspond à la valeur trouvée dans <parameter>haystack</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Si <parameter>needle</parameter> est une chaîne, la comparaison
|
|
est faîte 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 :
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Trouvé Linux
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>in_array</function> et le mode sctrict</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>
|
|
<para>
|
|
Ce script va afficher :
|
|
<screen role="php">
|
|
<![CDATA[
|
|
1.13 a été trouvé avec recherche stricte
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</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";
|
|
?>
|
|
|
|
// This will output:
|
|
|
|
'ph' a été trouvé
|
|
'o' a été trouvé
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Voir aussi
|
|
<function>array_search</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
|
|
-->
|