Psalm 35 is a plea to God from David to weigh in on his side against those who were troubling him without a cause (see verse 7). He had no idea where the animosity had come from, and for his part, he had behaved toward them like a friend:
But as for me, when they were sick,
My clothing was sackcloth;
I humbled myself with fasting;
And my prayer would return to my own heart.
I paced about as though he were my friend or brother;
I bowed down heavily, as one who mourns for his mother. (Psalm 35:13-14)
However, when he was down,
. . . they rejoiced
And gathered together;
Attackers gathered against me,
And I did not know it;
They tore at me and did not cease;
With ungodly mockers at feasts
They gnashed at me with their teeth. (Psalm 35:15-16)
To grasp the reason for David's statement in verse 18, it must be read in context with the previous verse:
Lord, how long will You look on?
Rescue me from their destructions,
My precious life from the lions.
I will give You thanks in the great assembly;
I will praise You among many people.
David felt alone and persecuted unjustly, and worst of all, he felt that God was merely sitting as a spectator in the stands of the arena, idly watching the spectacle of his being torn to pieces by the teeth and claws of ravenous lions, his enemies. Knowing how undeserved his trouble was, David cannot understand why God has not acted to save him before this. Verse 18 is a promise, along with the plea of verse 17, to praise God publicly and give Him all the glory for his deliverance (compare Psalm 22:22, 25; 40:9-10).
Specifically, he promises to praise God in the public worship at the Tabernacle, as this occurred before the building of the Temple, accomplished by David's son, Solomon. The phrase "many people" is elsewhere translated as "the throng" (see Psalm 42:4; 109:30), and in this case, the psalmist speaks of it, not just as a great number of people, but as a "mighty throng," implying great strength as well. It is doubtful, but there may be a suggestion here that the people of the assembly would be strengthened if they only knew the mighty works that God had performed on David's behalf.
The more cynical may see David's promise as a bribe of sorts, trying to finagle a miracle from God and vowing to repay Him with praise. Others may equate it with the desperate prayer of a soldier in the foxhole, promising to go to church every week if God will just preserve him through the battle. However, that is certainly not the case here. David is already fully committed to God, which he has proved over many years of service to Him, and in this particular psalm, by loving his enemies and waiting on Him for salvation.
The simple fact is that praise (through continued thanks, worship, and proclamation of God's goodness) is the only way a human being can "pay back" the great God of the universe for His blessings and aid. What can a man give to God? We have nothing that God needs; He owns everything already. David's promise, then, should be read as a pledge of joy (verse 9) to praise his Lord and proclaim his faith in God to the widest audience possible as a witness (verses 27b-28). He will do his part to show the world that his God is the God of salvation, one who comes to the aid of His people.