Pass values in array to user-defined function and return a string with array_reduce with initial parameter in PHP

Description

The following code shows how to pass values in array to user-defined function and return a string with array_reduce with initial parameter.

Example


//from   w w  w  . j  a  va  2  s .  co  m
<?php
function myfunction($v1,$v2){
    return $v1 . "-" . $v2;
}
$a=array("CSS","Data","Style");
print_r(array_reduce($a,"myfunction",5));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone