Acting on items in an array 1/3 at a time
- by Jason
I have an array that has 9 items in it (it may also have 7, 10 or 11 items in it)
$anArray = array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I');
I also have three variables:
$A='A'; $B='B'; $C='C';
I need change the first 1/3 of the items in the array from what they are to $A
...the 2nd third to $B
...and the final third to $C
Array([1]=>A [2]=>A [3]=>A [4]=>B [5]=>B [6]=>B [7]=>C [8]=>C [9]=>C)
Is there an easy and straight-forward way of doing this? Right now I'm doing lots of foreach with counters, etc... and it seems like to much work.