我有这个数组:
id
但我需要这样的群组ID:
[12] => Array
(
[groupID] => 19
[groupApprovalRefID] => 123433322
[jobrequisitionRefID] => eRS/2015/00023/021/HQ
[groupApprovalSubject] => Principle
[jobrequisitionGroupID] => 19
[groupCreatedDate] => 2015-05-13 14:43:55
[groupReference] => HQ/05/2015/016/00016
)
答案 0 :(得分:0)
您可以循环遍历数组的每个元素,并使用所需的索引创建一个新数组。
class MyForm(forms.Form):
myfield = forms.ChoiceField()
def __init__(self,*args,**kwargs):
super(MyForm,self).__init__(*args,**kwargs)
self.fields['myfield'].choices = [(u.id, u.username) for u in User.objects.filter(type="TYPE1")]
请注意,如果$result_array = array();
foreach ($original_array as $value)
{
$result_array[$value['groupID']] = $value;
}
不唯一,则某些值可能会丢失,因为PHP数组具有唯一索引。