$arr = [1, [2, 7, 8], [3, 4], [5, [6, 7]]];
function getSquare($arr) {
$res = [];
foreach($arr as $elem) {
if(is_array($elem)) {
array_push($res, getSquare($elem));
} else {
array_push($res, $elem*$elem);
}
}
return $res;
}
var_dump(getSquare($arr));
function getSquare(&$arr) {
foreach($arr as $i => &$elem) {
if(is_array($elem)) {
getSquare($elem);
} else {
$arr[$i] = $elem*$elem;
}
}
return $arr;
}