I'm doing this thing.
I have something like
$a[0][name] = "jack";
$a[0][age] = 10;
$a[1][name] = "some dewd"$a[1][age] = 11;
$a[2][name] = "yet anoter dewd";
$a[2][age] = 19;
Now, I want to do a check. If anyone is inserting a replicated name, it doesn't insert the new name, BUT increments the value of age.
the array_search function is nice for what I want because it returns the key where the value was found.
So, I would do something like
[need a loop here] [from 0 to sizeof ($a)]
if (array_search ( $name, $a[$i] )) {
$key = array_search ( $name, $a );
$a[$key][age] = $a[$key][age]+1;
}
else {
$key = sizeof ($a)+1;
$a[$key][name] = $name;
$a[$key][age] = $age;
}
[end the loop]
But, there are a few considerations make this NOT WORK.
The first is that, in this type of arrays, it doesn't return 0 or 1 (or..), it returns name.
This is something I can fix using the loop's index. I think. The problem is the other consideration.
The other consideration is that will only work if the loop loops. If the value o the array is 0 it aint going to loop.
But I need to loop because the array_search doesn't find the text if I don't specify a key.
Can someone enlight me towards a way of doing this?
Thanks in advance.