Contoh Show <?php function myfunction($v1,$v2) { return $v1 . "-" . $v2; } $a=array("Dog","Cat","Horse"); print_r(array_reduce($a,"myfunction")); ?> // Output : -Dog-Cat-Horse Definisi dan PenggunaanFungsi Catatan: Jika array kosong dan inisial tidak dilewatkan, fungsi ini mengembalikan NULL. Syntax
Nilai Parameter
Detail Teknis
Contoh LainContoh <?php function myfunction($v1,$v2) { return $v1 . "-" . $v2; } $a=array("Dog","Cat","Horse"); print_r(array_reduce($a,"myfunction",5)); ?> //Output : 5-Dog-Cat-Horse Contoh <?php function myfunction($v1,$v2) { return $v1+$v2; } $a=array(10,15,20); print_r(array_reduce($a,"myfunction",5)); ?> //Output : 50 <PHP Array Referensi ContohMengirimkan nilai-nilai dalam array ke fungsi yang ditentukan pengguna dan mengembalikan string: <?php Menjalankan contoh » Definisi dan PenggunaanThe array_reduce() fungsi mengirimkan nilai-nilai dalam array ke fungsi user-defined, dan mengembalikan string. Catatan: Jika array kosong dan awal tidak lulus, fungsi ini mengembalikan NULL. Sintaksisarray_reduce( array,myfunction,initial )
Rincian teknis
Contoh lebihcontoh 1Dengan parameter awal: <?php Menjalankan contoh » contoh 2Kembali penjumlahan: <?php Menjalankan contoh » <PHP Array Referensi (PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8) array_reduce — Iteratively reduce the array to a single value using a callback function Parametersarray The input array. callback carry Holds the return value of the previous iteration; in the case of the first iteration it
instead holds the value of item Holds the value of the current iteration. initial If the optional Return ValuesReturns the resulting value. If the array is empty and Changelog
ExamplesExample #1 array_reduce() example
product($carry, $item) See Also
Hayley Watson ¶ 14 years ago
directrix1 at gmail dot com ¶ 6 years ago
$formatted_attribs;?> souzacomprog at gmail dot com ¶ 2 years ago
= [ 849330489 at qq dot com ¶ 2 years ago
= function($x, $f){ Altreus ¶ 8 years ago
= [1,2,3,4];var_dump(array_reduce( magnesium dot oxide dot play+php at gmail dot com ¶ 8 years ago
= array(); php at keith tyler dot com ¶ 12 years ago
ruslan dot zavackiy at gmail dot com ¶ 10 years ago
$result;
kon ¶ 9 years ago
bdechka at yahoo dot ca ¶ 15 years ago
cwu at nolo dot com ¶ 6 years ago
Seanj.jcink.com ¶ 16 years ago
yuki [dot] kodama [at] gmail [dot] com ¶ 15 years ago
itsunclexo at gmail dot com ¶ 7 months ago
= "Hello";$frequencies = array_reduce(str_split($items), Julian Sawicki ¶ 2 years ago
galley dot meng at gmail dot com ¶ 5 years ago
= array();$two_dimensional['foo'] = array('a' => 1, 'b' => 2, 'c' => 3);
aiadfaris at yahoo dot de ¶ 8 years ago
aiadfaris at yahoo dot de ¶ 8 years ago
|