1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-24 15:32:36 +01:00
Files
archived-doc-es/reference/array/functions/array-map.xml
Leonardo Boshell d6106f6844 * Actualizaciones
* Correccion de errores apuntados en las notas de la documentacion (gracias
  a Nuno por mencionarlos en la lista)
* No seguir usando entidades para caracteres especiales


git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@210544 c90b9560-bf6c-de11-be94-00142212c4b1
2006-04-02 12:04:19 +00:00

240 lines
5.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.8 $ -->
<!-- EN-Revision: 1.16 Maintainer: lboshell Status: ready -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.62 -->
<refentry id="function.array-map">
<refnamediv>
<refname>array_map</refname>
<refpurpose>
Aplica la llamada de retorno especificada a los elementos de las
matrices dadas
</refpurpose>
</refnamediv>
<refsect1>
<title>Descripción</title>
<methodsynopsis>
<type>array</type><methodname>array_map</methodname>
<methodparam><type>callback</type><parameter>llamada_de_retorno</parameter></methodparam>
<methodparam><type>array</type><parameter>matriz1</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_map</function> devuelve una matriz que contiene
todos los elementos de <parameter>matriz1</parameter> después de
haber aplicado la función
<parameter>llamada_de_retorno</parameter> a cada uno de ellos. El
número de parámetros que la función
<parameter>llamada_de_retorno</parameter> acepte debería
coincidir con el número de matrices que son pasadas como
argumentos a <function>array_map</function>.
</para>
<para>
<example>
<title>Ejemplo de <function>array_map</function></title>
<programlisting role="php">
<![CDATA[
<?php
function cubo($n)
{
return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cubo", $a);
print_r($b);
?>
]]>
</programlisting>
<para>
Esto hace que <varname>$b</varname> contenga:
</para>
<screen>
<![CDATA[
Array
(
[0] => 1
[1] => 8
[2] => 27
[3] => 64
[4] => 125
)
]]>
</screen>
</example>
</para>
<para>
<example>
<title><function>array_map</function> - usando más
matrices</title>
<programlisting role="php">
<![CDATA[
<?php
function mostrar_Castellano($n, $m)
{
return("El número $n es llamado $m en Castellano");
}
function map_Castellano($n, $m)
{
return(array($n => $m));
}
$a = array(1, 2, 3, 4, 5);
$b = array("uno", "dos", "tres", "cuatro", "cinco");
$c = array_map("mostrar_Castellano", $a, $b);
print_r($c);
$d = array_map("map_Castellano", $a , $b);
print_r($d);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
// salida correspondiente a $c
Array
(
[0] => El número 1 es llamado uno en Castellano
[1] => El número 2 es llamado dos en Castellano
[2] => El número 3 es llamado tres en Castellano
[3] => El número 4 es llamado cuatro en Castellano
[4] => El número 5 es llamado cinco en Castellano
)
// salida correspondiente a $d
Array
(
[0] => Array
(
[1] => uno
)
[1] => Array
(
[2] => dos
)
[2] => Array
(
[3] => tres
)
[3] => Array
(
[4] => cuatro
)
[4] => Array
(
[5] => cinco
)
)
]]>
</screen>
</example>
</para>
<para>
Usualmente, cuando se usan dos o más matrices, éstas deberían ser
de longitudes iguales ya que la llamada de retorno es aplicada en
paralelo a los elementos correspondientes. Si las matrices son de
longitudes diferentes, la más corta de ellas será extendida con
elementos vacíos.
</para>
<para>
Un uso interesante de esta función es la construcción de una
matriz de matrices, que puede ser llevada a cabo usando &null;
como el nombre de la llamada de retorno.
</para>
<para>
<example>
<title>Creación de una matriz de matrices</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array(1, 2, 3, 4, 5);
$b = array("one", "two", "three", "four", "five");
$c = array("uno", "dos", "tres", "cuatro", "cinco");
$d = array_map(null, $a, $b, $c);
print_r($d);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[0] => 1
[1] => one
[2] => uno
)
[1] => Array
(
[0] => 2
[1] => two
[2] => dos
)
[2] => Array
(
[0] => 3
[1] => three
[2] => tres
)
[3] => Array
(
[0] => 4
[1] => four
[2] => cuatro
)
[4] => Array
(
[0] => 5
[1] => five
[2] => cinco
)
)
]]>
</screen>
</example>
</para>
<para>
Vea también <function>array_filter</function>,
<function>array_reduce</function>,
<function>array_walk</function>,
<function>create_function</function>, y &seealso.callback;.
</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
-->