Magento 2 - Get Collection using custom product Ids and also sort them as the same order as product Ids passed
You just need to add order along with your addAttributeToFilter
$collection->addAttributeToFilter('entity_id', array('in' => $productIdsarray ));
$collection->getSelect()->order(new \Zend_Db_Expr("FIELD(e.entity_id, ".implode(",",$productIdsarray).")"));