Array
(
[0] => Array
(
[0] => OLAO01
[1] => OLAO01
[2] => BARR04
[3] => OLAO01
[4] => MADD03
)
[1] => Array
(
[0] => BARR04
[1] => POWE03
)
[2] => Array
(
[0] => BARR04
[1] => COLL09
)
[3] => Array
(
[0] => BARR04
[1] => SARC01
[2] => OLAO01
)
[4] => Array
(
[0] => BARR04
[1] => HORS02
)
[5] => Array
(
[0] => BARR04
)
[6] => Array
(
[0] => OLAO01
)
[7] => Array
(
[0] => RYDE02
)
[9] => Array
(
[0] => CAMP02
)
[10] => Array
(
[0] => WRIG05
[1] => CAMP02
[2] => LEMO01
)
[11] => Array
(
[0] => OLAO01
)
[12] => Array
(
[0] => HIPP01
[1] => LEMO01
)
)
I have array like this I needs to find if how many time one value repeating consecutive BARR04
Repeated 6 times. But if one array not that value then for that counter it will set to 1 again
$result = array_intersect($newary[$i], $newary[$i+1]);
I tried with this but not working properly
2
Answers
Just iterate through the subarrays and keep track of the consecutive occurrences of
"BARR04"
:You can flatten the array and count how many times a value occurs. Like this:
Use like this: