Send each value in array to a function, and return an array with the new values in PHP

Description

The following code shows how to send each value in array to a function, and return an array with the new values.

Example


//from  w w w .j  a v  a2 s.c om
<?php
function myfunction($v){
     return($v*$v);
}

$a=array(1,2,3,4,5);
print_r(array_map("myfunction",$a));
?>

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