I have an array that I want to loop through and make it's elements copy the previous elements's value using PHP.
array [
17 => "x",
16 => "x",
15 => "x",
14 => "108.7000",
13 => "x",
12 => "x",
11 => "x",
10 => "x",
09 => "108.2635",
08 => "x",
07 => "x",
06 => "x",
05 => "x",
04 => "x",
03 => "x",
02 => "x",
01 => "x",
00 => "x",
23 => "x",
22 => "x",
21 => "x",
20 => "x",
19 => "x",
18 => "x"
]
For example, the output should be:
array [
17 => "108.7000",
16 => "108.7000",
15 => "108.7000",
14 => "108.7000",
13 => "108.2635",
12 => "108.2635",
11 => "108.2635",
10 => "108.2635",
09 => "108.2635",
08 => "108.2635",
07 => "108.2635",
06 => "108.2635",
05 => "108.2635",
04 => "108.2635",
03 => "108.2635",
02 => "108.2635",
01 => "108.2635",
00 => "108.2635",
23 => "108.2635",
22 => "108.2635",
21 => "108.2635",
20 => "108.2635",
19 => "108.2635",
18 => "108.2635"
]
as you can see keys above 14 became 108.7000, the letter 'x' will always be there, that is how I want to check. I can't get my head around this, maybe I even haven't used the right wording to describe the question.
look at the key 09 it has a value of 108.2635, below that are all x, which means they all should copy 09's value and above 09 until 04 are also x values, which means they also should be 108.2635, key 14 has its own value and above it are again x values which means they should copy 14's value