067 - Array Reduce ,
-orange-banana-apple

067-a - Array Reduce , Passing third parameter as a Initial Value
lemon-orange-banana-apple

067-b - Array Reduce-2
20-orange-banana-apple

067-c - Array Reduce, Use Numeric Index array
20-1-2-3-4-5

067-d - Array Reduce, sum all values in the array
15

067-e - Array Reduce, mutiplication
0

067-f - Array Reduce, with third parameters
1200

067-g - Array Reduce addition, with third parameters
25
<?php // 067 - Array Reduce , echo "</br><span class='myheading'>067 - Array Reduce , </span></br>"; function myFunction($n,$m){ return $n . "-" . $m; } $a = ['orange', 'banana', 'apple']; $newArray = array_reduce($a, 'myFunction'); echo "<pre>"; print_r($newArray); echo "</pre>"; // 067-a - Array Reduce-1 , Passing third parameter as a Initial Value echo "</br><span class='myheading'>067-a - Array Reduce , Passing third parameter as a Initial Value </span></br>"; $newArray1 = array_reduce($a, 'myFunction', "lemon"); echo "<pre>"; print_r($newArray1); echo "</pre>"; // 067-b - Array Reduce-2 echo "</br><span class='myheading'>067-b - Array Reduce-2</span></br>"; $newArray2 = array_reduce($a, 'myFunction', 20); echo "<pre>"; print_r($newArray2); echo "</pre>"; // 067-c - Array Reduce, Use Numeric Index array echo "</br><span class='myheading'>067-c - Array Reduce, Use Numeric Index array </span></br>"; $a1 = [1, 2, 3, 4, 5]; $newArray3 = array_reduce($a1, 'myFunction', 20); echo "<pre>"; print_r($newArray3); echo "</pre>"; // 067-d - Array Reduce, sum all values in the array echo "</br><span class='myheading'>067-d - Array Reduce, sum all values in the array</span></br>"; $a1 = [1, 2, 3, 4, 5]; function myFunction1($n,$m){ /* sum */ return $n + $m; } $newArray4 = array_reduce($a1, 'myFunction1'); echo "<pre>"; print_r($newArray4); echo "</pre>"; // 067-e - Array Reduce, mutiplication echo "</br><span class='myheading'>067-e - Array Reduce, mutiplication</span></br>"; $a1 = [1, 2, 3, 4, 5]; function myFunction2($n,$m){ /* Multiplication */ return $n * $m; } $newArray5 = array_reduce($a1, 'myFunction2'); echo "<pre>"; print_r($newArray5); echo "</pre>"; // 067-f - Array Reduce, with third parameters echo "</br><span class='myheading'>067-f - Array Reduce, with third parameters</span></br>"; $a1 = [1, 2, 3, 4, 5]; $newArray6 = array_reduce($a1, 'myFunction2',10); /* -------Pass third Initial Parameter-------*/ echo "<pre>"; print_r($newArray6); echo "</pre>"; // 067-g - Array Reduce addition, with third parameters echo "</br><span class='myheading'>067-g - Array Reduce addition, with third parameters</span></br>"; $a1 = [1, 2, 3, 4, 5]; function myFunction3($n,$m){ /* Additon, Can also right */ //$n =$n + $m; $n += $m; return $n; } $newArray7 = array_reduce($a1, 'myFunction3',10); echo "<pre>"; print_r($newArray7); echo "</pre>"; ?>