I'd like to check an array of image filenames to see how many consecutive images have the same orientation using PHP.
In the following example, I'd like to know that indexes 1 through 4 have the same orientation OR that there are four consecutive images with the same orientation at the first index.
For reference, "orientation" values are "V" for vertical and "H" for horizontal.
e.g.,
Array
(
[0] => Array
(
[filename] => image0.jpg
[orientation] => V
)
[1] => Array
(
[filename] => image1.jpg
[orientation] => H
)
[2] => Array
(
[filename] => image2.jpg
[orientation] => H
)
[3] => Array
(
[filename] => image3.jpg
[orientation] => H
)
[4] => Array
(
[filename] => image4.jpg
[orientation] => H
)
[5] => Array
(
[filename] => image5.jpg
[orientation] => V
)
[...]
[n]
}
There has to be a better way than
if ([i]['orientation'] == [i+1]['orientation'])
if ([i]['orientation'] == [i+1]['orientation'] == [i+2]['orientation'])
if ([i]['orientation'] == [i+1]['orientation'] == [i+2]['orientation'] == [i+3]['orientation'])
if ([i]['orientation'] == [i+1]['orientation'] == [i+2]['orientation'] == [i+3]['orientation'] == [i+4]['orientation'])