I hav completed the dispersed pair or not from array list. But it is not given the correct array (same number of key) as when I enter the input array list. Here I am forwarding my code,,
Code: Select all
function matchUp($array) {
$result = array();
while($el = array_pop($array)) {
shuffle($array);
if (sizeof($array) > 0) {
$candidate = array_pop($array);
$result[] = array(array_pop($el),array_pop($candidate));
if (sizeof($el) > 0) {
$array[] = $el;
}
if (sizeof($candidate) > 0) {
$array[] = $candidate;
}
}
else {
$result[] = array(array_pop($el));
}
}
return $result;
}
$input_array = array("S1","S2","S3","S4","S5","S6","S7","S8");
$pair_set = array_slice($input_array, 0,6);
$dispersed_set = array_slice($input_array,6);
$array_p = array_chunk($pair_set, 2);
$array_s = array_chunk($dispersed_set, 1);
echo '<pre>';
$array = array_merge($array_p,$array_s);
// It is an input array list....
print_r($array);
echo '</pre>';
// It is an output array list....
print_r(matchup($array));