Tuesday, 1 October 2013

php array values compare

php array values compare

Hi people I need your help. Let's say I have an array.
$arr = array(
1 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 3,
keyx...),
2 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 0,
keyx...),
3 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 2,
keyx...),
4 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 2,
keyx...),
5 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 3,
keyx...),
6 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 0,
keyx),
7 => array(
key1 => something,
key2 => something,
key3 => something,
testkey => 3,
keyx...),
n =>array(blabla)
)
I can't know how many keys $arr has.
I need to test if one or more value of testkey are equal, if they are put
this result on a variable.
2 and 6 are not considered since the testkey is 0.
(0 is my default value, i can put it to NULL)
5 and 6 have the value of 1 (first to match).
1, 5 and 7 have the value of 2 (second to match).
Then I have to store this values somehow:
$matched = array();
$matched[1] = array (2, 6);
$matched[2] = array (1, 5, 7);
But I'm sure it can be done better.
Thank you.

No comments:

Post a Comment