mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 15:12:23 +01:00
196 lines
4.9 KiB
XML
196 lines
4.9 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: c84024092aee02b51dd18b909af0f2ccbdd24f98 Maintainer: lhsazevedo Status: ready --><!-- CREDITS: felipe, lucasr, fabioluciano, lhsazevedo -->
|
|
<refentry xml:id="function.array-diff" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_diff</refname>
|
|
<refpurpose>Computa as diferenças entre arrays</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_diff</methodname>
|
|
<methodparam><type>array</type><parameter>array</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>array</type><parameter>arrays</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Compara <parameter>array</parameter> com um ou mais arrays e
|
|
retorna os valores no <parameter>array</parameter> que não estão presentes em
|
|
nenhum dos outros arrays.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
O array a ser comparado
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>arrays</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Arrays para comparar
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna um <type>array</type> contendo todas as entradas de
|
|
<parameter>array</parameter> que não estão presentes em nenhum dos outros arrays.
|
|
Chaves no array <parameter>array</parameter> são preservadas.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
&array.changelog.require-only-one;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo da função <function>array_diff</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array1 = array("a" => "verde", "vermelho", "azul", "vermelho");
|
|
$array2 = array("b" => "verde", "amarelo", "vermelho");
|
|
$result = array_diff($array1, $array2);
|
|
|
|
print_r($result);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Multiplas ocorrências de <varname>$array1</varname> são todas tratadas da mesma maneira.
|
|
Isto irá mostrar:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => azul
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>array_diff</function> com tipos não correspondentes</title>
|
|
<para>
|
|
Dois elementos são considerados iguais se e somente se
|
|
<literal>(string) $elem1 === (string) $elem2</literal>. Isto é,
|
|
quando a <link linkend="language.types.string.casting">representação em string</link> é a mesma.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Isto irá gerar uma Notícia de que um array não pode ser convertido em uma string.
|
|
$fonte = [1, 2, 3, 4];
|
|
$filtro = [3, 4, [5], 6];
|
|
$resultado = array_diff($fonte, $filtro);
|
|
|
|
// Enquanto isto não é um problema, uma vez que o objeto pode ser convertido em string.
|
|
class S {
|
|
private $v;
|
|
|
|
public function __construct(string $v) {
|
|
$this->v = $v;
|
|
}
|
|
|
|
public function __toString() {
|
|
return $this->v;
|
|
}
|
|
}
|
|
|
|
$fonte = [new S('a'), new S('b'), new S('c')];
|
|
$filtro = [new S('b'), new S('c'), new S('d')];
|
|
|
|
$resultado = array_diff($fonte, $filtro);
|
|
|
|
// $resultado agora contém uma instância de S('a');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Para usar uma função de comparação alternativa, veja <function>array_udiff</function>.
|
|
</para>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Esta função verifica somente uma dimensão de um array n-dimensional. É claro
|
|
que as dimensões mais profundas podem ser verificadas usando
|
|
<literal>array_diff($array1[0], $array2[0]);</literal>.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_diff_assoc</function></member>
|
|
<member><function>array_udiff</function></member>
|
|
<member><function>array_intersect</function></member>
|
|
<member><function>array_intersect_assoc</function></member>
|
|
</simplelist>
|
|
</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:"~/.phpdoc/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
|
|
-->
|