mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@172709 c90b9560-bf6c-de11-be94-00142212c4b1
165 lines
4.4 KiB
XML
165 lines
4.4 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.4 $ -->
|
|
<!-- EN-Revision: 1.17 Maintainer: baoengb Status: ready -->
|
|
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
|
|
<refentry id="function.each">
|
|
<refnamediv>
|
|
<refname>each</refname>
|
|
<refpurpose>
|
|
Devuelve el siguiente par clave/valor de una matriz y avanza el apuntador
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descripción</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>each</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">matriz</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve el par clave/valor actual para la
|
|
<parameter>matriz</parameter> y avanza el puntero de la
|
|
misma. Esta pareja se devuele en una matriz de 4 elementos,
|
|
con las claves
|
|
<emphasis>0</emphasis>, <emphasis>1</emphasis>,
|
|
<emphasis>key</emphasis>, y
|
|
<emphasis>value</emphasis>. Los elementos <emphasis>0</emphasis> y
|
|
<emphasis>key</emphasis> contienen el nombre de clave
|
|
del elemento de la matriz, y <emphasis>1</emphasis> y
|
|
<emphasis>value</emphasis> contienen los datos.
|
|
</para>
|
|
<para>
|
|
Si el puntero interno para la matriz apunta después del final del
|
|
contenido de la matriz, <function>each</function> devuelve &false;.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Ejemplos de <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$chorrada = array ("bob", "fred", "jussi", "jouni", "egon", "marliese");
|
|
$tonteria = each ($chorrada);
|
|
print_r($tonteria);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
<varname>$tonteria</varname> ahora contiene los siguientes pares de
|
|
llave/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>$tonteria</varname> ahora contiene los siguientes pares de
|
|
llave/valor:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Bob
|
|
[value] => Bob
|
|
[0] => Robert
|
|
[key] => Robert
|
|
)
|
|
]]>
|
|
</screen>
|
|
</informalexample>
|
|
</para>
|
|
<para>
|
|
<function>each</function> se usa normalmente de forma conjunta a
|
|
<function>list</function> para recorrer una matriz; por ejemplo:
|
|
<example>
|
|
<title>Recorriendo una matriz con <function>each</function></title>
|
|
<programlisting role="php">
|
|
<![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>
|
|
<para>
|
|
Cuando se ha ejecutado <function>each</function>, el cursor de la
|
|
matriz quedará en el siguiente elemento de la misma, o en el
|
|
último si llega al final de ésta. Tiene que usar
|
|
<function>reset</function> si quiere recorrer la matriz otra vez
|
|
usando each.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
A causa de que asignar una matriz a otra variable reinicia el apuntador
|
|
original de la matriz, nuestro ejemplo anterior pudo causar un
|
|
ciclo sin fin tuvimos que asignar <varname>$fruit</varname> a otra variable
|
|
dentro del ciclo.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
Vea también: <function>key</function>,
|
|
<function>list</function>,
|
|
<function>current</function>,
|
|
<function>reset</function>,
|
|
<function>next</function>,
|
|
<function>prev</function>, y
|
|
<link linkend="control-structures.foreach">foreach</link>.
|
|
</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:"../../../../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
|
|
-->
|