mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 07:22:16 +01:00
Use consistent line terminator. git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@317671 c90b9560-bf6c-de11-be94-00142212c4b1
199 lines
5.1 KiB
XML
199 lines
5.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 96c9d88bad9a7d7d44bfb7f26c226df7ee9ddf26 Maintainer: seros Status: ready -->
|
|
<refentry xml:id="function.each" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>each</refname>
|
|
<refpurpose>Devolver el par clave/valor actual de un array y avanzar el cursor del array</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>each</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve el par clave/valor actual de un array y avanza el cursor del
|
|
array.
|
|
</para>
|
|
<para>
|
|
Después de que <function>each</function> haya sido ejecutado, el cursor del array
|
|
será puesto en el siguiente elemento del array, o pasado el último
|
|
elemento si alcanza el final del array. Se tiene que usar
|
|
<function>reset</function> si se quiere atravesar de nuevo el
|
|
array usando each.
|
|
</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 dado por
|
|
<parameter>array</parameter>. Este par es devuelto en un array de cuatro
|
|
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 del
|
|
elemento del array, y <literal>1</literal> y <literal>value</literal>
|
|
contienen la información.
|
|
</para>
|
|
<para>
|
|
Si el puntero interno del array apunta al final del contenido de
|
|
array, <function>each</function> devuelve
|
|
&false;.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> ahora contienelos siguientes pares
|
|
clave/valor:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => bob
|
|
[value] => bob
|
|
[0] => 0
|
|
[key] => 0
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<informalexample>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
|
|
$bar = each($foo);
|
|
print_r($bar);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$bar</varname> ahora contienelos siguientes pares
|
|
clave/valor:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Bob
|
|
[value] => Bob
|
|
[0] => Robert
|
|
[key] => Robert
|
|
)
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<function>each</function> se usa normalmente junto con
|
|
<function>list</function> para atravesar un array. Aquí hay un
|
|
ejemplo:
|
|
<example>
|
|
<title>Atravesar un array con <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fruta = array('a' => 'manzana', 'b' => 'banana', 'c' => 'arándano');
|
|
|
|
reset($fruta);
|
|
while (list($clave, $valor) = each($fruta)) {
|
|
echo "$clave => $valor\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
a => manzana
|
|
b => banana
|
|
c => arándano
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
Ya que asignar un array a otra variable reinicia el puntero del array
|
|
original (nuestro ejemplo de arriba causaría un bucle sin fin), hemos
|
|
asignado <varname>$fruta</varname> a otra variable dentro del
|
|
bucle.
|
|
</para>
|
|
</caution>
|
|
<warning>
|
|
<para>
|
|
<function>each</function> también aceptará objetos, pero puede devolver resultados
|
|
inesperados. Por lo tanto, no se recomienda iterar propiedades de objetos
|
|
con <function>each</function>.
|
|
</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
|
|
-->
|