INSERT. . . SELECT should be able to handle multiples correct?
$a = array(1, 2, 3, 17);
$sql = "INSERT INTO persons (P_ID, coding) "
." SELECT P_ID, coding FROM othertable WHERE P_ID IN (" . implode(', ', $a) . ")";
Slightly less mess. Otherwise, a loop with a prepared statement would probably be alright.