Php Modify All Elements in Array

If there is need to change all elements in array, you need to read this article.

array_map() is used for modify all variables in array. You don’t need to use for loop. array_map() walks in all elements and change.

[php]
function cube($n)
{
return($n * $n * $n);
}

$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);
[/php]

This is output

[html]
Array
(
[0] => 1
[1] => 8
[2] => 27
[3] => 64
[4] => 125
)
[/html]