My switch case allows me to find the values which match one of a list of values
I need to extend this code/logic so that I can collect all consecutive keys starting from the first occurring C or D until the element before the second occurring C or D.
Here is what I would like to do:
foreach ($array as $key => $value) {
switch($value) {
case "C":
case "D":
// Store all keys from "C" until I come across a second value "C" or "D"
}
}
Here is an example:
$array =
(
[53] => q
[61] => f
[74] => s
[87] => C
[19] => D
[101] => e
[22] => C
[13] => h
)
Result: "87 19 101"