How to destroy a block and give you an item in your inventory at the same time?

Here is an answer that works no matter how many players there are.

Place down an always active repeating command chain of 2 blocks.

Commands inside:

  1. Tell everyone with a red_mushroom under them to give themselves an item.

    /execute @a ~ ~ ~ detect ~ ~-1 ~ red_mushroom 0 give @s mushroom
    
  2. Tell everyone with with a red_mushroom under them to set the block underneath them to air.

    /execute @a ~ ~ ~ detect ~ ~-1 ~ red_mushroom 0 setblock ~ ~-1 ~ air
    

There is a simple fix to this:

Have a Repeat command block set to Always Active, with this command:

/execute @a ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air

There is a house/pentagon-shaped object with dots on it, and it should be on top, and pointing to a chain command block.

The chain command block should have your command that gives the player a mushroom, set to Always Active, and Conditional. The Conditional statement is there for this reason:

If the Repeat command block detects a player on a mushroom, then they will give that player a mushroom. If not, then nothing happens. If the block was Unconditional, then players would have their inventories cluttered with mushrooms. I hope this helps.

Edit: Because we want to detect which player stepped on a mushroom, we need separate pairs of command blocks for each player, like so:

/execute fasterthanlight ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give fasterthanlight red_mushroom 1

For each player, set up a different pair of command blocks with these commands, and replace my username with your targeted player. For example, with two players, Alice and Bob, two pairs of blocks will be used:

/execute Alice ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give Alice red_mushroom 1

and

/execute Bob ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give Bob red_mushroom 1