<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.array.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.array-key-exists.php',
    1 => 'array_key_exists',
    2 => 'V&eacute;rifie si une cl&eacute; existe dans un tableau',
  ),
  'up' => 
  array (
    0 => 'ref.array.php',
    1 => 'Fonctions sur les tableaux',
  ),
  'prev' => 
  array (
    0 => 'function.array-is-list.php',
    1 => 'array_is_list',
  ),
  'next' => 
  array (
    0 => 'function.array-key-first.php',
    1 => 'array_key_first',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/array/functions/array-key-exists.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.array-key-exists" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">array_key_exists</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_key_exists</span> &mdash; <span class="dc-title">Vérifie si une clé existe dans un tableau</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.array-key-exists-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_key_exists</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.float.php" class="type float">float</a></span>|<span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>|<span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$key</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$array</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>array_key_exists()</strong></span> retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> s&#039;il existe une
   clé du nom de <code class="parameter">key</code> dans le tableau
   <code class="parameter">array</code>. <code class="parameter">key</code>
   peut être n&#039;importe quelle valeur valide d&#039;index
   de tableau.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.array-key-exists-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">key</code></dt>
     <dd>
      <p class="para">
       Valeur à vérifier.
      </p>
     </dd>
    
    
     <dt><code class="parameter">array</code></dt>
     <dd>
      <p class="para">
       Un tableau contenant les clés à vérifier.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.array-key-exists-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Cette fonction retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>array_key_exists()</strong></span> va rechercher, uniquement, dans
    les clés de la première dimension. Les clés imbriquées dans les
    tableaux multidimensionnels ne seront pas trouvées
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.array-key-exists-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.5.0</td>
      <td>
       L’utilisation de <span class="type"><a href="language.types.null.php" class="type null">null</a></span> dans le paramètre <code class="parameter">key</code> est obsolète, utiliser une chaîne vide à la place.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Le paramètre <code class="parameter">key</code> accepte désormais
       les arguments de type <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>, <span class="type"><a href="language.types.float.php" class="type float">float</a></span>, <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>,
       <span class="type"><a href="language.types.null.php" class="type null">null</a></span>, <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>, et
       <span class="type"><a href="language.types.string.php" class="type string">string</a></span>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Il n&#039;est plus possible de passer un <span class="type"><a href="language.types.object.php" class="type object">object</a></span> au paramètre <code class="parameter">array</code>.
      </td>
     </tr>

     <tr>
      <td>7.4.0</td>
      <td>
       Il est déconseillé de passer un <span class="type"><a href="language.types.object.php" class="type object">object</a></span> au paramètre <code class="parameter">array</code>. Utiliser plutôt <span class="function"><a href="function.property-exists.php" class="function">property_exists()</a></span>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.array-key-exists-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>array_key_exists()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$searchArray </span><span style="color: #007700">= [</span><span style="color: #DD0000">'first' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'second' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">4</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'first'</span><span style="color: #007700">, </span><span style="color: #0000BB">$searchArray</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(true)</pre>
</div>
    </div>
   </div>
  </p>
  <div class="example" id="example-2">
   <p><strong>Exemple #2 <span class="function"><strong>array_key_exists()</strong></span> et <span class="function"><a href="function.isset.php" class="function">isset()</a></span></strong></p>
   <div class="example-contents"><p>
    <span class="function"><a href="function.isset.php" class="function">isset()</a></span> ne retourne pas <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> pour les clés de 
    tableaux qui correspondent à une valeur <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> alors que c&#039;est le 
    cas pour <span class="function"><strong>array_key_exists()</strong></span>.
   </p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$searchArray </span><span style="color: #007700">= [</span><span style="color: #DD0000">'first' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">null</span><span style="color: #007700">, </span><span style="color: #DD0000">'second' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">4</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(isset(</span><span style="color: #0000BB">$searchArray</span><span style="color: #007700">[</span><span style="color: #DD0000">'first'</span><span style="color: #007700">]));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">array_key_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'first'</span><span style="color: #007700">, </span><span style="color: #0000BB">$searchArray</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(false)
bool(true)</pre>
</div>
   </div>
  </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.array-key-exists-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.isset.php" class="function" rel="rdfs-seeAlso">isset()</a> - D&eacute;termine si une variable est d&eacute;clar&eacute;e et est diff&eacute;rente de null</span></li>
    <li><span class="function"><a href="function.array-keys.php" class="function" rel="rdfs-seeAlso">array_keys()</a> - Retourne toutes les cl&eacute;s ou un ensemble des cl&eacute;s d'un tableau</span></li>
    <li><span class="function"><a href="function.in-array.php" class="function" rel="rdfs-seeAlso">in_array()</a> - Indique si une valeur appartient &agrave; un tableau</span></li>
    <li><span class="function"><a href="function.property-exists.php" class="function" rel="rdfs-seeAlso">property_exists()</a> - V&eacute;rifie si un objet ou une classe poss&egrave;de une propri&eacute;t&eacute;</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>