1
0
mirror of https://github.com/php/doc-es.git synced 2026-04-25 08:08:27 +02:00
Files
archived-doc-es/reference/array/functions/list.xml
T
Yago Ferrer 4a2bed8052 More files from: 'lboshell'
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@297985 c90b9560-bf6c-de11-be94-00142212c4b1
2010-04-14 10:23:56 +00:00

160 lines
4.0 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<!-- EN-Revision: n/a Maintainer: baoengb Status: Ready -->
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
<refentry xml:id="function.list" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>list</refname>
<refpurpose>
Asigna variables como si fueran una matriz
</refpurpose>
</refnamediv>
<refsect1>
<title>Descripción</title>
<methodsynopsis>
<type>void</type><methodname>list</methodname>
<methodparam><type>mixed</type><parameter>varname</parameter></methodparam>
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
Como <function>array</function>, esta no es realmente una función,
sino una construcción del lenguaje. <function>list</function> se
usa para asignar una lista de variables en una sola operación.
</para>
<note>
<para>
<function>list</function> solo funciona con matrices numéricas y
asume que el índice numérico empieza en 0.
</para>
</note>
<para>
<example>
<title>Ejemplo de <function>list</function></title>
<programlisting role="php">
<![CDATA[
<?php
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
// Listing some of them
list($drink, , $power) = $info;
echo "$drink has $power.\n";
// Or let's skip to only the third one
list( , , $power) = $info;
echo "I need $power!\n";
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Otro ejemplo del uso de <function>list</function></title>
<programlisting role="php">
<![CDATA[
<table>
<tr>
<th>Employee name</th>
<th>Salary</th>
</tr>
<?php
$result = mysql_query("SELECT id, name, salary FROM employees", $conn);
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
echo " <tr>\n" .
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
" <td>$salary</td>\n" .
" </tr>\n";
}
?>
</table>
]]>
</programlisting>
</example>
</para>
<warning>
<para>
<function>list</function> asigna los valores comenzando por el
parámetro m&aacute;s a la derecha. Si est&aacute; usando variables
independientes, no tiene que preocuparse acerca de esto. Pero si está
usando matrices con índices usualmente se esperar&iacute;a
tener el orden de los índices en la matriz en la misma forma que se
se escribió en la funci&oacute;n <function>list</function> de
izquierda a derecha; lo cuál no ocurrir&aacute;, son asignados en
orden inverso.
</para>
</warning>
<para>
<example>
<title>Usando <function>list</function> con matrices coníndices
</title>
<programlisting role="php">
<![CDATA[
<?php
$info = array('coffee', 'brown', 'caffeine');
list($a[0], $a[1], $a[2]) = $info;
var_dump($a);
?>
]]>
</programlisting>
<para>
Da la siguiente salida (note el orden de los elementos comparado en
el orden en el que fueron escritos en la función
<function>list</function>):
</para>
<screen>
<![CDATA[
array(3) {
[2]=>
string(8) "caffeine"
[1]=>
string(5) "brown"
[0]=>
string(6) "coffee"
}
]]>
</screen>
</example>
</para>
<para>
Vea también: <function>each</function>,
<function>array</function> y
<function>extract</function>.
</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
-->