Skip to content

Instantly share code, notes, and snippets.

@ivansky
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivansky/08576139b26b24665ea7 to your computer and use it in GitHub Desktop.
Save ivansky/08576139b26b24665ea7 to your computer and use it in GitHub Desktop.
<?php
$source = [
'color' => ['red','blue','white','yellow','black'],
'who' => ['rabbit','bear','wolf'],
'else' => ['in space','in Russia','is hungry','is dead']
];
var_dump(recursion_calculate($source));
function recursion_vars(array $arr, array $arr2){
$result = array();
foreach($arr as $v){
foreach($arr2 as $v2){
$result[] = array_merge($v, $v2);
}
}
return $result;
}
function recursion_calculate(array $arr){
foreach ($arr as $k => $in) {
foreach ($in as $t => $val){
$arr[$k][$t] = array($k => $val);
}
}
$source = false;
foreach ($arr as $key => $array){
if($source == false){
$source = $array;
continue;
}
$source = recursion_vars($source, $array);
}
return $source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment