1
0
mirror of https://github.com/php/doc-pl.git synced 2026-04-27 08:48:05 +02:00
Files
archived-doc-pl/reference/array/functions/array-map.xml
T
Hartmut Holzgraefe a8c9a462d9 banana-split
git-svn-id: https://svn.php.net/repository/phpdoc/pl/trunk@78217 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-15 01:39:52 +00:00

215 lines
5.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-2"?>
<!-- splitted from ./pl/functions/array.xml, last change in rev 1.1 -->
<!-- last change to 'array-map' in en/ tree in rev 1.62 -->
<!-- EN-Revision: 1.1 Maintainer: leszek Status: ready -->
<!-- OLD-Revision: 1.130/EN.1.62 -->
<refentry id="function.array-map">
<refnamediv>
<refname>array_map</refname>
<refpurpose>
Wykonuje funkcjê zwrotn± na elementach podanej tablicy
</refpurpose>
</refnamediv>
<refsect1>
<title>Opis</title>
<methodsynopsis>
<type>array</type><methodname>array_map</methodname>
<methodparam><type>mixed</type><parameter>funkcja_zwrotna</parameter></methodparam>
<methodparam><type>array</type><parameter>tbl1</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>tbl2...</parameter></methodparam>
</methodsynopsis>
<para>
<function>array_map</function> zwraca tablicê zawieraj±c± wszystkie
elementy tablicy <parameter>tbl1</parameter> po u¿yciu na ka¿dej z nich
funkcji zwrotnej. Liczba parametrów funkcji zwrotnej powinna byæ równa
liczbie tablic przekazanych do funkcji <function>array_map</function>.
</para>
<para>
<example>
<title>Przyk³ad u¿ycia <function>array_map</function></title>
<programlisting role="php">
<![CDATA[
function szescian($n) {
return $n*$n*$n;
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("szescian", $a);
]]>
</programlisting>
</example>
</para>
<para>
W powy¿szej funkcji tablica <varname>$b</varname> zawiera
<literal>array (1, 8, 27, 64, 125);</literal>
</para>
<para>
<example>
<title>
<function>array_map</function> - u¿ywanie wiêkszej ilo¶ci tablic
</title>
<programlisting role="php">
<![CDATA[
function pokaz_po_Hiszpansku($n, $m) {
return "Po Hiszpañsku liczba $n to $m";
}
function mapuj_na_Hiszpanski($n, $m) {
return array ($n => $m);
}
$a = array(1, 2, 3, 4, 5);
$b = array("uno", "dos", "tres", "cuatro", "cinco");
$c = array_map("pokaz_po_Hiszpansku", $a, $b);
print_r($c);
// will output:
// Array
// (
// [0] => Po Hiszpañsku liczba 1 to uno
// [1] => Po Hiszpañsku liczba 2 to dos
// [2] => Po Hiszpañsku liczba 3 to tres
// [3] => Po Hiszpañsku liczba 4 to cuatro
// [4] => Po Hiszpañsku liczba 5 to cinco
// )
$d = array_map("mapuj_po_Hiszpansku", $a , $b);
print_r($d);
// wy¶wietli:
// Array
// (
// [0] => Array
// (
// [1] => uno
// )
//
// [1] => Array
// (
// [2] => dos
// )
//
// [2] => Array
// (
// [3] => tres
// )
//
// [3] => Array
// (
// [4] => cuatro
// )
//
// [4] => Array
// (
// [5] => cinco
// )
//
// )
]]>
</programlisting>
</example>
</para>
<para>
Zazwyczaj u¿ywaj±c dwóch lub wiêcej tablic, powinny one byæ równej
d³ugo¶ci, poniewa¿ funkcja zwrotna jest wykonywana na odpowiadaj±cych
sobie elementach tablic.
Je¶li tablice s± ró¿nych d³ugo¶ci, krótsze bêd± rozszerzane u¿ywaj±c
pustych elementów.
</para>
<para>
Interesuj±cym sposobem u¿ycia tej funkcji jest kontruowanie tablicy
tablic, co mo¿e byæ ³atwo przeprowadzone przez podanie &null; jako nazwy
funkcji zwrotnej.
</para>
<para>
<example>
<title>Tworzenie tablicy tablic</title>
<programlisting role="php">
<![CDATA[
$a = array(1, 2, 3, 4, 5);
$b = array("one", "two", "three", "four", "five");
$c = array("uno", "dos", "tres", "cuatro", "cinco");
$d = array("jeden", "dwa", "trzy", "cztery", "piêæ");
$e = array_map(null, $a, $b, $c, $d);
print_r($e);
// wy¶wietli:
// Array
// (
// [0] => Array
// (
// [0] => 1
// [1] => one
// [2] => uno
// [3] => jeden
// )
//
// [1] => Array
// (
// [0] => 2
// [1] => two
// [2] => dos
// [3] => dwa
// )
//
// [2] => Array
// (
// [0] => 3
// [1] => three
// [2] => tres
// [3] => trzy
// )
//
// [3] => Array
// (
// [0] => 4
// [1] => four
// [2] => cuatro
// [3] => cztery
// )
//
// [4] => Array
// (
// [0] => 5
// [1] => five
// [2] => cinco
// [3] => piêæ
// )
//
// )
]]>
</programlisting>
</example>
</para>
<para>
Patrz tak¿e <function>array_filter</function>,
<function>array_reduce</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
-->