map() public static method

Recursive array mapping
public static map ( Closure $function, array $array ) : array
$function Closure
$array array
return array
コード例 #1
0
ファイル: ArrayTest.php プロジェクト: jbzoo/utils
 public function testMapRecursive()
 {
     $array = array(1, 2, 3, 4, 5);
     $result = Arr::map(function ($number) {
         return $number * $number;
     }, $array);
     is(array(1, 4, 9, 16, 25), $result);
     $array = array(1, 2, 3, 4, 5, array(6, 7, array(8, array(array(array(9))))));
     $result = Arr::map(function ($number) {
         return $number * $number;
     }, $array);
     is(array(1, 4, 9, 16, 25, array(36, 49, array(64, array(array(array(81)))))), $result);
 }