Skip to content

Instantly share code, notes, and snippets.

@antcolag
Last active January 8, 2020 10:52
Show Gist options
  • Save antcolag/a9e44d3cad126ab71149aee91e5928b8 to your computer and use it in GitHub Desktop.
Save antcolag/a9e44d3cad126ab71149aee91e5928b8 to your computer and use it in GitHub Desktop.
php function for unpack arrays
<?php
$array = [
"Complimenti",
"ora",
"puoi",
[
"inviare",
[
"la tua",
"candidatura!"
]
]
];
function compute($curr, ...$arr){
$result = "";
switch(gettype($curr)){
case "string":
$result .= $curr;
break;
case "array":
$result .= compute(...$curr);
break;
default:
}
if(count($arr) == 0){
return $result;
}
return $result . " " . compute(...$arr);
}
echo compute(...$array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment