I've created two arrays from strings using explode()
one called $labels
and the other called $colors
. What I'd like to do is check the count of the items in $labels
and if there are less items in $colors
I'd like the values of the $colors
array to be repeated until the count matches. If there are more items in $colors
than in $labels
I'd like to reduce remove items from the $colors
array until it matches the number of items in $labels
.
I assume I can use count()
or array_legnth()
in a conditional to compare the number of items between the two arrays and that I'm going to have to use some kind of while loop but really not sure how to get started.
Is there a better way or function I should use to compare the two arrays? And how would I go about repeating or deleting the items in the second array so that I land up with the same number of items in each?