My aim to create multiple possible of out comes with 3 arrays.
I achieved it but i got struck with one problem.
I find there is repeated values with different keys.
below is the code i tried to generate .
$top = array(array('toplinner_name' => M1), array('toplinner_name' => M2));
$flute1 = array(array('f1_name' => M3));
$single_array = compares($top, $flute1); //combaining arrays
$bottom = array(array('bottomlinner_name' => M1), array('bottomlinner_name' => M2));
$single_array = compares($single_array, $bottom); //combaining arrays
function compares($a, $b) {
if (is_array($a) && is_array($b)) {
if (count($a) < count($b)) {
list($a, $b) = array($b, $a);
}
$new = array();
$k = 0;
for ($i = 0; $i < count($b); $i++) {
for ($j = 0; $j < count($a); $j++) {
$new[$k] = array_merge($b[$i], $a[$j]);
$k++;
}
}
return $new;
}
return null;
}
with the above code i am getting out put as
Array{
'0'=>{'toplinner_name'=>'M1','f1_name'=>'M3','bottomlinner_name'=>'M1'},
'2'=>{'toplinner_name'=>'M1','f1_name'=>'M3','bottomlinner_name'=>'M2'},
'3'=>{'toplinner_name'=>'M2','f1_name'=>'M3','bottomlinner_name'=>'M1'},
'4'=>{'toplinner_name'=>'M2','f1_name'=>'M3','bottomlinner_name'=>'M2'},
}
As you can see from the above out put 2 and 3 are same linners so i need t0 consider them as one how can i remove those duplicate values..... i tried below code
$input = array_map("unserialize", array_unique(array_map("serialize", $new)));
but it gives me same out put.
my desired out put should be
Array{
'0'=>{'toplinner_name'=>'M1','f1_name'=>'M3','bottomlinner_name'=>'M1'},
'1'=>{'toplinner_name'=>'M1','f1_name'=>'M3','bottomlinner_name'=>'M2'},
'2'=>{'toplinner_name'=>'M2','f1_name'=>'M3','bottomlinner_name'=>'M2'},
}
$input = array_unique($new);
? – Gavriel Feb 1 '16 at 7:01SORT_REGULAR
like this:$input = array_unique($new, SORT_REGULAR);
– Rein Feb 1 '16 at 7:13