Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

array reduce function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php array reduce () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 4 >= 4.0.5, PHP 5)

array_reduce --  Iteratively reduce the array to a single value using a callback function

Syntax

mixed array_reduce ( array input, callback function [, int initial] )

array_reduce() applies iteratively the function function to the elements of the array input, so as to reduce the array to a single value. If the optional initial is available, it will be used at the beginning of the process, or as a final result in case the array is empty.

Example 1. array_reduce() example

<?php
function rsum($v, $w)
{
    
$v += $w;
    return
$v;
}

function
rmul($v, $w)
{
    
$v *= $w;
    return
$v;
}

$a = array(1, 2, 3, 4, 5);
$x = array();
$b = array_reduce($a, "rsum");
$c = array_reduce($a, "rmul", 10);
$d = array_reduce($x, "rsum", 1);
?>

This will result in $b containing 15, $c containing 1200 (= 1*2*3*4*5*10), and $d containing 1.

See also array_filter(), array_map(), array_unique(), and array_count_values().

Php array reduce Function syntax tag

array reduce php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php array reduce syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online