<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >preg_grep</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="Regular Expression Functions (Perl-Compatible)" HREF="ref.pcre.html"><LINK REL="PREVIOUS" TITLE="Pattern Syntax" HREF="reference.pcre.pattern.syntax.html"><LINK REL="NEXT" TITLE="preg_last_error" HREF="function.preg-last-error.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="reference.pcre.pattern.syntax.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.preg-last-error.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.preg-grep" ></A >preg_grep</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN166729" ></A ><P > (PHP 4, PHP 5)</P >preg_grep -- Return array entries that match the pattern</DIV ><DIV CLASS="refsect1" ><A NAME="AEN166732" ></A ><H2 >Descrição</H2 >array <B CLASS="methodname" >preg_grep</B > ( string pattern, array input [, int flags] )<BR ></BR ><P > Returns the array consisting of the elements of the <CODE CLASS="parameter" >input</CODE > array that match the given <CODE CLASS="parameter" >pattern</CODE >. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN166749" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >pattern</CODE ></DT ><DD ><P > The pattern to search for, as a string. </P ></DD ><DT ><CODE CLASS="parameter" >input</CODE ></DT ><DD ><P > The input array. </P ></DD ><DT ><CODE CLASS="parameter" >flags</CODE ></DT ><DD ><P > If set to <TT CLASS="constant" ><B >PREG_GREP_INVERT</B ></TT >, this function returns the elements of the input array that do <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > match the given <CODE CLASS="parameter" >pattern</CODE >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN166771" ></A ><H2 >Valores de retornado</H2 ><P > Returns an array indexed using the keys from the <CODE CLASS="parameter" >input</CODE > array. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN166775" ></A ><H2 >Histórico</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN166778" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Versão</TH ><TH >Descrição</TH ></TR ></THEAD ><TBODY ><TR ><TD >4.2.0</TD ><TD > The <CODE CLASS="parameter" >flags</CODE > parameter was added. </TD ></TR ><TR ><TD >4.0.4</TD ><TD > <P > Prior to this version, the returned array was indexed regardless of the keys of the <CODE CLASS="parameter" >input</CODE > array. </P > <P > If you want to reproduce this old behavior, use <A HREF="function.array-values.html" ><B CLASS="function" >array_values()</B ></A > on the returned array to reindex the values. </P > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN166796" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN166799" ></A ><P ><B >Exemplo 1. <B CLASS="function" >preg_grep()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// return all array elements<br />// containing floating point numbers<br /></font><font color="#0000BB">$fl_array </font><font color="#007700">= </font><font color="#0000BB">preg_grep</font><font color="#007700">(</font><font color="#DD0000">"/^(\d+)?\.\d+</font><font color="#007700">$</font><font color="#DD0000">/"</font><font color="#007700">, </font><font color="#0000BB">$array</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </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="reference.pcre.pattern.syntax.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.preg-last-error.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Pattern Syntax</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.pcre.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >preg_last_error</TD ></TR ></TABLE ></DIV ></BODY ></HTML >