1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-25 16:02:13 +01:00
Files
archived-doc-es/reference/array/functions/list.xml
Enrique Garcia Briones 43207f68e3 sync con version inglesa
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@179321 c90b9560-bf6c-de11-be94-00142212c4b1
2005-02-09 14:43:51 +00:00

160 lines
4.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- EN-Revision: 1.14 Maintainer: baoengb Status: Ready -->
<!-- splitted from ./es/functions/array.xml, last change in rev 1.1 -->
<refentry id="function.list">
<refnamediv>
<refname>list</refname>
<refpurpose>
Asigna variables como si fueran una matriz
</refpurpose>
</refnamediv>
<refsect1>
<title>Descripci&oacute;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&oacute;n,
sino una construcci&oacute;n del lenguaje. <function>list</function> se
usa para asignar una lista de variables en una sola operaci&oacute;n.
</para>
<note>
<para>
<function>list</function> solo funciona con matrices num&eacute;ricas y
asume que el &iacute;ndice num&eacute;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&aacute;metro m&aacute;s a la derecha. Si est&aacute; usando variables
independientes, no tiene que preocuparse acerca de esto. Pero si est&aacute;
usando matrices con &iacute;ndices usualmente se esperar&iacute;a
tener el orden de los &iacute;ndices en la matriz en la misma forma que se
se escribi&oacute; en la funci&oacute;n <function>list</function> de
izquierda a derecha; lo cu&aacute;l no ocurrir&aacute;, son asignados en
orden inverso.
</para>
</warning>
<para>
<example>
<title>Usando <function>list</function> con matrices con&iacute;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&oacute;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&eacute;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
-->