Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 7331

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>in_array</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Arrays"
HREF="ref.array.html"><LINK
REL="PREVIOUS"
TITLE="extract"
HREF="function.extract.html"><LINK
REL="NEXT"
TITLE="key"
HREF="function.key.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.extract.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.key.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.in-array"
></A
>in_array</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN12637"
></A
><P
>    (PHP 4, PHP 5)</P
>in_array&nbsp;--&nbsp;Checa se um valor existe em um array</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN12640"
></A
><H2
>Descrição</H2
>bool <B
CLASS="methodname"
>in_array</B
> ( mixed needle, array haystack [, bool strict] )<BR
></BR
><P
>&#13;     Procura em <CODE
CLASS="parameter"
>haystack</CODE
> pelo valor
     <CODE
CLASS="parameter"
>needle</CODE
> e retorna <TT
CLASS="constant"
><B
>TRUE</B
></TT
> 
     se este valor for encontrado no array, e <TT
CLASS="constant"
><B
>FALSE</B
></TT
> em caso contrário.
    </P
><P
>&#13;     Se o terceiro parâmetro <CODE
CLASS="parameter"
>strict</CODE
> for
     <TT
CLASS="constant"
><B
>TRUE</B
></TT
> então <B
CLASS="function"
>in_array()</B
>
     também irá checar os <A
HREF="language.types.html"
>tipos</A
> de
     <CODE
CLASS="parameter"
>needle</CODE
> em <CODE
CLASS="parameter"
>haystack</CODE
>.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Se <CODE
CLASS="parameter"
>needle</CODE
> for uma string, a comparação é feita
      diferenciando caracteres maiúsculos e minúsculos.
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Em versões do PHP mais antigas que 4.2.0 <CODE
CLASS="parameter"
>needle</CODE
>
      não pode ser um array.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN12673"
></A
><P
><B
>Exemplo 1. Exemplo de <B
CLASS="function"
>in_array()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$os </font><font color="#007700">= array(</font><font color="#DD0000">"Mac"</font><font color="#007700">, </font><font color="#DD0000">"NT"</font><font color="#007700">, </font><font color="#DD0000">"Irix"</font><font color="#007700">, </font><font color="#DD0000">"Linux"</font><font color="#007700">); <br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(</font><font color="#DD0000">"Irix"</font><font color="#007700">, </font><font color="#0000BB">$os</font><font color="#007700">)) { <br />&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"Tem Irix"</font><font color="#007700">;<br />}<br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(</font><font color="#DD0000">"mac"</font><font color="#007700">, </font><font color="#0000BB">$os</font><font color="#007700">)) { <br />&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"Tem mac"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>&#13;       A segunda condicional falha pois <B
CLASS="function"
>in_array()</B
>
       diferencia letras minúsculas e maiúsculas. Então, a saída seria:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Got Irix</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN12681"
></A
><P
><B
>Exemplo 2. <B
CLASS="function"
>in_array()</B
> com checagem de tipos</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$a </font><font color="#007700">= array(</font><font color="#DD0000">'1.10'</font><font color="#007700">, </font><font color="#0000BB">12.4</font><font color="#007700">, </font><font color="#0000BB">1.13</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(</font><font color="#DD0000">'12.4'</font><font color="#007700">, </font><font color="#0000BB">$a</font><font color="#007700">, </font><font color="#0000BB">TRUE</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"'12.4' encontrado com checagem de tipo\n"</font><font color="#007700">;<br />}<br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(</font><font color="#0000BB">1.13</font><font color="#007700">, </font><font color="#0000BB">$a</font><font color="#007700">, </font><font color="#0000BB">TRUE</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"1.13 encontrado com checagem de tipo\n"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>&#13;       A saída seria:
      </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>1.13 encontrado com checagem de tipo</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN12688"
></A
><P
><B
>Exemplo 3. Exemplo de <B
CLASS="function"
>in_array()</B
> passando um array para <CODE
CLASS="parameter"
>needle</CODE
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$a </font><font color="#007700">= array(array(</font><font color="#DD0000">'p'</font><font color="#007700">, </font><font color="#DD0000">'h'</font><font color="#007700">), array(</font><font color="#DD0000">'p'</font><font color="#007700">, </font><font color="#DD0000">'r'</font><font color="#007700">), </font><font color="#DD0000">'o'</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(array(</font><font color="#DD0000">'p'</font><font color="#007700">, </font><font color="#DD0000">'h'</font><font color="#007700">), </font><font color="#0000BB">$a</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"'ph' foi encontrado\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(array(</font><font color="#DD0000">'f'</font><font color="#007700">, </font><font color="#DD0000">'i'</font><font color="#007700">), </font><font color="#0000BB">$a</font><font color="#007700">)) { <br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"'fi' foi encontrado\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />if (</font><font color="#0000BB">in_array</font><font color="#007700">(</font><font color="#DD0000">'o'</font><font color="#007700">, </font><font color="#0000BB">$a</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"'o' foi encontrado\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Outputs: <br />&nbsp;&nbsp;&nbsp;&nbsp;'ph' was found <br />&nbsp;&nbsp;&nbsp;&nbsp;'o' was found <br />&nbsp;&nbsp;&nbsp;&nbsp;*/<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Veja também <A
HREF="function.array-search.html"
><B
CLASS="function"
>array_search()</B
></A
>,
     <A
HREF="function.array-key-exists.html"
><B
CLASS="function"
>array_key_exists()</B
></A
> e
     <A
HREF="function.isset.html"
><B
CLASS="function"
>isset()</B
></A
>.  
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.extract.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.key.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>extract</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.array.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>key</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>