Count the occurrence of two variable in php
I have 2 variables which were defined in a 2 dimensional for loop which
correspond to x and y coordinates.
$coordx,$coordy;
I put them into an array and want to find out the frequency of the
combination of $coordx and $coordy. For example:
$coordx = 10, $coordy=15
$coordx = 1, $coordy =25
$coordx = 10, $coordy =15
The combination of $coordx and $coordy would show (10,15) occurs twice and
(10,15) occurs once.
I have tried to merge them into one variable and then into an array
$results which is the concatenation of the two: $merge = $coordx.$coordy;
But, when I try to array_count_values($results) , I get the error message:
Warning: array_count_values() [function.array-count-values]: Can only
count STRING and INTEGER values!
Anyone know how to convert a concatenated variable into an integer. Or, is
there an easier way to count the occurrence to a two coordinate
value(x,y). Thanks
No comments:
Post a Comment