mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
242 lines
5.2 KiB
XML
242 lines
5.2 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- EN-Revision: 0987e913fcaed76897aeb239c6ed83d765a895e1 Maintainer: leonardolara Status: ready --><!-- CREDITS: narigone,lucasr,felipe,lhsazevedo,airtonzanon,leonardolara -->
|
|
<refentry xml:id="function.array-unshift" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_unshift</refname>
|
|
<refpurpose>Adiciona um ou mais elementos no início de um array</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>array_unshift</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_unshift</function> adiciona os elementos passados como
|
|
argumentos no início de <parameter>array</parameter>. Note que a lista
|
|
de elementos é adicionada como um todo, de forma que eles ficam na
|
|
mesma ordem. Todas as chaves numéricas serão modificadas para começar a
|
|
contar de zero enquanto chaves literais permanecerão inalteradas.
|
|
</para>
|
|
¬e.reset-index;
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
O array de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>values</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Os valores a serem adicionados.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retorna o novo número de elementos em <parameter>array</parameter>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>7.3.0</entry>
|
|
<entry>
|
|
Essa função agora pode ser chamada com apenas um parâmetro. Anteriomente, pelo
|
|
menos dois parâmetros eram necessários.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemplo de <function>array_unshift</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$cesta = [
|
|
"laranja",
|
|
"banana"
|
|
];
|
|
|
|
array_unshift($cesta, "melancia", "morango");
|
|
|
|
var_dump($cesta);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
array(4) {
|
|
[0] =>
|
|
string(8) "melancia"
|
|
[1] =>
|
|
string(7) "morango"
|
|
[2] =>
|
|
string(7) "laranja"
|
|
[3] =>
|
|
string(6) "banana"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Uso de arrays associativos</title>
|
|
<para>
|
|
Se um array associativo é pre anexado a outro array associativo,
|
|
o array anexado é numeralmente indexado no array anterior.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$frutas = [
|
|
'maca' => [
|
|
'McIntosh' => 'vermelho',
|
|
'Granny Smith' => 'verde',
|
|
],
|
|
'laranja' => [
|
|
'Navel' => 'laranja',
|
|
'Valencia' => 'laranja',
|
|
],
|
|
];
|
|
|
|
$vegetais = [
|
|
'alface' => [
|
|
'Iceberg' => 'verde',
|
|
'Butterhead' => 'verde',
|
|
],
|
|
'cenoura' => [
|
|
'Deep Purple Hybrid' => 'roxo',
|
|
'Imperator' => 'laranja',
|
|
],
|
|
'pepino' => [
|
|
'Kirby' => 'verde',
|
|
'Gherkin' => 'verde',
|
|
],
|
|
];
|
|
|
|
array_unshift($frutas, $vegetais);
|
|
|
|
var_dump($frutas);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
array(3) {
|
|
[0]=>
|
|
array(3) {
|
|
["alface"]=>
|
|
array(2) {
|
|
["Iceberg"]=>
|
|
string(5) "verde"
|
|
["Butterhead"]=>
|
|
string(5) "verde"
|
|
}
|
|
["cenoura"]=>
|
|
array(2) {
|
|
["Deep Purple Hybrid"]=>
|
|
string(4) "roxo"
|
|
["Imperator"]=>
|
|
string(7) "laranja"
|
|
}
|
|
["pepino"]=>
|
|
array(2) {
|
|
["Kirby"]=>
|
|
string(5) "verde"
|
|
["Gherkin"]=>
|
|
string(5) "verde"
|
|
}
|
|
}
|
|
["maca"]=>
|
|
array(2) {
|
|
["McIntosh"]=>
|
|
string(8) "vermelho"
|
|
["Granny Smith"]=>
|
|
string(5) "verde"
|
|
}
|
|
["laranja"]=>
|
|
array(2) {
|
|
["Navel"]=>
|
|
string(7) "laranja"
|
|
["Valencia"]=>
|
|
string(7) "laranja"
|
|
}
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_merge</function></member>
|
|
<member><function>array_shift</function></member>
|
|
<member><function>array_push</function></member>
|
|
<member><function>array_pop</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
|
|
-->
|