I have an array that has 22 items in it (it may also have 7, 10 or 11 items in it)
Old, crappy example: $anArray = array(1=>’A’,2=>’B’,3=>’C’,4=>’D’,5=>’E’,6=>’F’,7=>’G’,8=>’H’,9=>’I’);
Better example:
Array(
[25] => #
[50] => #
[53] => #
[55] => #
[56] => #
[57] => #
[58] => #
[59] => #
[60] => #
[61] => #
[62] => #
[63] => #
[64] => #
[65] => #
[66] => #
[67] => #
[68] => #
[69] => #
[70] => #
[71] => #
[72] => #
[73] => #)
I also have three variables:
$A='A'; $B='B'; $C='C';
I need change the first 1/3(*ish) of the items in the array from what they are to $A
…the 2nd third to $B
…and the final third to $C
Old, crappy example:Array([1]=>A [2]=>A [3]=>A [4]=>B [5]=>B [6]=>B [7]=>C [8]=>C [9]=>C)
Better example:
Array(
[25] => A
[50] => A
[53] => A
[55] => A
[56] => A
[57] => A
[58] => A
[59] => B
[60] => B
[61] => B
[62] => B
[63] => B
[64] => B
[65] => B
[66] => B
[67] => C
[68] => C
[69] => C
[70] => C
[71] => C
[72] => C
[73] => 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.
Also…The keys cannot change…sorry.
*By ish I mean about a third – 7-8-7 or 7-7-8 would work fine
ok, with the keys preserved