Php SilverStripe按确切顺序获取id

Php SilverStripe按确切顺序获取id,php,sql,silverstripe,Php,Sql,Silverstripe,假设您有一个密钥数组 $key_list = array(3, 6, 2); 您希望从某个表中检索记录,使用这些键作为标识符(其中ID=ID\u from\u key\u list) 这将返回ID与$key_list(3、6和2)中的ID匹配的行,但不按该顺序返回 检索这些项目时,我们如何保持相同的顺序?您可能需要做的是运行ID的foreah循环,并将每个Foo对象推送到ArrayList中 $aFooList = ArrayList::create(); foreach ($key_lis

假设您有一个密钥数组

$key_list = array(3, 6, 2);
您希望从某个表中检索记录,使用这些键作为标识符(其中ID=ID\u from\u key\u list)

这将返回ID与
$key_list
(3、6和2)中的ID匹配的行,但不按该顺序返回


检索这些项目时,我们如何保持相同的顺序?

您可能需要做的是运行ID的foreah循环,并将每个Foo对象推送到ArrayList中

$aFooList = ArrayList::create(); 
foreach ($key_list as $key_list_id){
   $oFoo = Foo::get()->byID($key_list_id);
   $aFooList->push($oFoo); 
}
return $aFooList;
$aFooList = ArrayList::create(); 
foreach ($key_list as $key_list_id){
   $oFoo = Foo::get()->byID($key_list_id);
   $aFooList->push($oFoo); 
}
return $aFooList;