You are stuck because you are trying to create an enumerated array when you really want to group this by the identifier of the array. Just use the id field as the target index:
foreach ($in as $src) {
extract($src);
$output[$id]["id"] = $id;
$output[$id]["payment_period"] = $payment_period;
$output[$id]["payment_types"][] = array(
"plan_payment_type_id" => $plan_payment_type_id,
"payment_type_id" => $payment_type_id,
);
}
Of course, you can use the long variable names $ src [] instead of the evil extract () label.
, $id, id = = $id.