【发布时间】:2015-10-13 13:41:55
【问题描述】:
我有一个随机性问题。 我有示例数组。
$example=array(
'F1' => array('test','test1','test2','test5'),
'F2' => array('test3', 'test4'),
'F3' => array('one','twoo','threee','x'),
'F5' => array('wow')
)
我想从数组中选择随机键到具有指定大小的其他数组。在第二个数组中,我想要其他组的值。
例如我得到了
$amounts = array(4,3,1,2,1);
我想从 $example 中选择随机指定的变量数量 ($amount),但当然 - 总是来自其他组。
示例结果:
$result=(
array(4) => ('test','test4','x','wow'),
array(3) => ('test2','test3','three'),
array(1) => ('test1')
array(2) => ('test5','one')
array(1) => ('twoo')
到目前为止我尝试了什么?
foreach($amounts as $key=>$amount){
$random_key[$key]=array_rand($example,$amount);
foreach($result[$key] as $key2=>$end){
$todelete=array_rand($example[$end]);
$result[$key][$key2]=$example[$amount][$todelete]
}
}
我现在不知道要解决什么问题或下一步该做什么。
感谢您的帮助!
【问题讨论】: