- print_r: documentation ( source)
<?php
function array_map_custom($array, $callable) {
$result = [];
foreach($array as $item) {
$result[] = $callable($item);
}
return $result;
}
$arr = [1, 2, 3, 4];
$newArr = array_map_custom(
$arr,
function($x){
return $x*$x;
});
print_r($newArr);