I am trying to find the most efficient way to get every fifth item in an array and then modify it with a str_replace.
For example to modify the [3r] to [4r] only every fifth item.
$myArray = array(“apples[3r]”, “jacobs[3r]”, “chocolate[3r]”, “makeup[3r]”, “lipstick[3r]”, “triangle[3r]”, “jacobson[3r]”, “lacksasf[3r]”,”dahe[3r]”, “applestoapples[3r]”, “coaxale[3r]”, “hamburger[3r]”, “prefix[3r]”
And this to output
apples[3r] jacobs[3r] chocolate[3r] makeup[3r] lipstick[4r] triangle[3r] jacobson[3r] lacksasf[3r] dahe[3r] applestoapples[4r] coaxale[3r] hamburger[3r] prefix[3r]
Using a “for” starting from 4 (the 5th element of your array) and increasing 5 every step:
EDIT: I forgot to assign the result to the array again.