Hi,
Would like to remove a value from an array. I have tried the following method but it doesn't work quite really well. Thus, I hope someone could improvise my method or suggest a totally new method to me.
This is the array that I currently have.
PHP Code:
// An array of Date > Weight > Name
Array
(
[2009-04-04] => Array
(
[0.15] => Array
(
[0] => Choo
)
[1.05] => Array
(
[0] => Faiz
[1] => Tan
[2] => Murawala
[3] => Modi
[4] => Zou
[5] => Hamid
[6] => Ng
[7] => Nur
[8] => Ritik
[9] => Cheang
)
[0.45] => Array
(
[0] => Quek
)
)
)
// Another array with different date but same data
Array
(
[2009-04-05] => Array
(
[0.15] => Array
(
[0] => Choo
)
[1.05] => Array
(
[0] => Faiz
[1] => Tan
[2] => Murawala
[3] => Modi
[4] => Zou
[5] => Hamid
[6] => Ng
[7] => Nur
[8] => Ritik
[9] => Cheang
)
[0.45] => Array
(
[0] => Quek
)
)
)
Base on the above, I have few dates but with same data on those dates. I want to randomly generate a name out from each date, however, considering to get the name from the highest weight first. Then remove the name from the array. Subsequently, after all the name from the highest weight gone, it will move to the next highest weight.
Though I have yet to work on the 'move to the next highest weight' thingy.
I have this current codes with me.
PHP Code:
foreach ($weekend as $WEEKENDS) {
// Set an array where each date of the weekend is assigned with a list of personnels.
$officerDateList = array($WEEKENDS => $kj);
// Get the Highest Weight Value
$max_key_val = max(array_keys($officerDateList[$WEEKENDS]));
// Randomly select one personnel out from the array.
$inputSDOduty[] .= array_multi_rand($officerDateList[$WEEKENDS][$max_key_val]);
// After one personnel has been selected, we have to remove him from the list to prevent same name from being selected again.
$officerDateList[$WEEKENDS][$max_key_val] = array_diff($officerDateList[$WEEKENDS][$max_key_val], $inputSDOduty);
$officerDateList[$WEEKENDS][$max_key_val] = array_values($officerDateList[$WEEKENDS][$max_key_val]);
}
function array_multi_rand($array) {
srand((float) microtime() * 10000000);
$key = array_rand($array);
if (is_array($array[$key])) {
return array_multi_rand($array[$key]);
} else {
return ($array[$key]);
}
}
Any suggestion? Thanks.