#57. PHP Array_Reduce Function

How to work PHP Array_Reduce Function?

E.g


Run code:

<?php

function myFun($a, $b){
    // return $a . "-" . $b;
    //return $a + $b;
    return $a * $b;

}

$c = [1,2,3,4,5];

//$c = ["MG","Civic","Alto","Mehran","Carola"];

//$newArr = array_reduce($c,'myFun', "Sazuki"); // inial (optional)

$newArr = array_reduce($c,'myFun', 1);
echo "<pre>";
print_r($newArr);
echo "</pre>";

Comments

Popular posts from this blog

#30. PHP Recursive Function