1
0
mirror of https://github.com/php/doc-fr.git synced 2026-03-25 15:42:16 +01:00
Files
archived-doc-fr/reference/array/functions/in-array.xml
Damien Seguy dabd551680 spring cleaning
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@114911 c90b9560-bf6c-de11-be94-00142212c4b1
2003-02-06 03:55:39 +00:00

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 &agrave; 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&egrave;me param&egrave;tre <parameter>strict</parameter> est
optionnel. S'il vaut &true; alors <function>in_array</function>
v&eacute;rifiera aussi que le types du param&egrave;tre <parameter>needle</parameter>
correspond &agrave; la valeur trouv&eacute;e dans <parameter>haystack</parameter>.
</para>
<note>
<para>
Si <parameter>needle</parameter> est une cha&icirc;ne, la comparaison
est fa&icirc;te en tenant compte de la casse.
</para>
</note>
<note>
<para>
Dans les versions ant&eacute;rieure &agrave; 4.2.0, <parameter>needle</parameter> ne pouvait
pas &ecirc;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&eacute; Linux";
}
if (in_array ("mac", $os)) {
print "Trouv&eacute; mac";
}
?>
]]>
</programlisting>
<para>
La seconde condition &eacute;choue, car <function>in_array</function>
est sensible &agrave; la casse. Le script retourne :
<screen role="php">
<![CDATA[
Trouv&eacute; 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 &eacute;t&eacute; trouv&eacute; avec recherche stricte\n";
if (in_array(1.13, $a, TRUE))
echo "1.13 a &eacute;t&eacute; trouv&eacute; avec recherche stricte\n";
?>
]]>
</programlisting>
<para>
Ce script va afficher :
<screen role="php">
<![CDATA[
1.13 a &eacute;t&eacute; trouv&eacute; avec recherche stricte
]]>
</screen>
</para>
</example>
</para>
<para>
<example>
<title>Exemple avec <function>in_array</function> et deux tableaux en param&egrave;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 &eacute;t&eacute; trouv&eacute;\n";
if (in_array(array ('f', 'i'), $a))
echo "'fi' a &eacute;t&eacute; trouv&eacute;\n";
if (in_array('o', $a))
echo "'o' a &eacute;t&eacute; trouv&eacute;\n";
?>
// This will output:
'ph' a &eacute;t&eacute; trouv&eacute;
'o' a &eacute;t&eacute; trouv&eacute;
]]>
</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
-->