PHP Programing language

array_reduce() Function in PHP
Previous Home Next

array_reduce()

The array_reduce() function sends the values in an array to a user-defined function, and returns a string.

Syntax:
array_reduce(array,myfunction,initial)

In above syntax, "array" specifies an array, "myfunction" specifies the name of the function and "initial" specifies the initial value to send to the function

Example:

<?php
function myfunction($var1,$var2)
{
return $var1 . "or" . $var2;
}
$arr=array(" Apple "," Orange "," Mango ");
print_r(array_reduce($arr, "myfunction",1));
?>

Output:

1 or Apple or Orange or Mango

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: