Postgresql Plpgsql Loop Through Array Of Objects Php