mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
202 lines
5.3 KiB
XML
202 lines
5.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<!-- CREDITS: DavidA. -->
|
|
<refentry xml:id="function.each" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>each</refname>
|
|
<refpurpose>Devuelve cada par clave/valor de un array</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsynopsisdiv>
|
|
&warn.deprecated.function-7-2-0.removed-8-0-0;
|
|
</refsynopsisdiv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>each</methodname>
|
|
<methodparam><type class="union"><type>array</type><type>object</type></type><parameter role="reference">array</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>each</function> devuelve el par clave/valor actual del array
|
|
<parameter>array</parameter> y avanza el puntero del array.
|
|
</para>
|
|
<para>
|
|
Tras cada llamada a <function>each</function>, el puntero del array se
|
|
desplaza al siguiente elemento, o más allá del último elemento, cuando se llega
|
|
al final. Debe utilizarse <function>reset</function> si se desea recorrer
|
|
el array nuevamente con <function>each</function>.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El array de entrada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve el par clave/valor actual del array
|
|
<parameter>array</parameter> y avanza el puntero
|
|
del array. Este par se devuelve en un array
|
|
de 4 elementos, con las claves <literal>0</literal>, <literal>1</literal>,
|
|
<literal>key</literal>, y <literal>value</literal>. Los
|
|
elementos <literal>0</literal> y <literal>key</literal>
|
|
contienen el nombre de la clave y <literal>1</literal> y
|
|
<literal>value</literal> contienen el valor.
|
|
</para>
|
|
<para>
|
|
Si el puntero interno del array está más allá del final del array,
|
|
<function>each</function> devuelve &false;.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>each</function></title>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> contiene ahora las claves/valores siguientes :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => bob
|
|
[value] => bob
|
|
[0] => 0
|
|
[key] => 0
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<informalexample>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> contiene ahora las claves/valores siguientes :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Bob
|
|
[value] => Bob
|
|
[0] => Robert
|
|
[key] => Robert
|
|
)
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<function>each</function> se utiliza típicamente en conjunción
|
|
con <function>list</function> para revisar un array.
|
|
Por ejemplo :
|
|
<example>
|
|
<title>Recorrer un array con <function>each</function></title>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
|
|
|
|
reset($fruit);
|
|
while (list($key, $val) = each($fruit)) {
|
|
echo "$key => $val\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
a => apple
|
|
b => banana
|
|
c => cranberry
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
Asignar un array a otra variable reinicia el puntero del array original
|
|
a cero. Debido a este comportamiento, se podría haber provocado una
|
|
iteración infinita en nuestro ejemplo si se hubiera asignado
|
|
<varname>$fruit</varname> a otra variable dentro de nuestro ciclo.
|
|
</para>
|
|
</caution>
|
|
<warning>
|
|
<para>
|
|
<function>each</function> también acepta objetos, pero puede devolver
|
|
un resultado no esperado. Por lo tanto, no se recomienda utilizar esta
|
|
función con objetos.
|
|
</para>
|
|
</warning>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>key</function></member>
|
|
<member><function>list</function></member>
|
|
<member><function>current</function></member>
|
|
<member><function>reset</function></member>
|
|
<member><function>next</function></member>
|
|
<member><function>prev</function></member>
|
|
<member>&foreach;</member>
|
|
<member><link linkend="language.oop5.iterations">Iteración de objetos</link></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
|
|
-->
|