How to get array which can remember past price when past criteria is met?

I have this array criteria_arr. It defines when the price meets certain criteria. I want to output an array price_memory_arr such that it has memory effect which allows it to remember the past close price when the criteria is met. New price is updated when criteria is met again.

This is how the desired price_memory_arr should look like.

criteria_arr =        [1    0   0    0    1   0   0    1   0];
price_memory_arr =    [2.2 2.2 2.2  2.2  3.1 3.1 3.1  4.1 4.1];   //desired output

The closest code I think of is
price_memory_arr = IIf(criteria_arr , Close, 0);
The problem is that the output does not have memory effect. The output will look like this;
price_memory_arr = [2.2 0 0 0 3.1 0 0 4.1 0]; //wrong output

I just found out the answer.

price_memory_arr = ValueWhen(criteria_arr, close, n=1);