Forum Moderators: coopster
let's say we have an array like this one:
$my_array = array("a"=>"1", "b"=>"2", "c"=>"3");
// the pairs are $my_name=>$my_number
In our example 1,2,3 are numbers (counts, ids, timestamps etc), and they are all integers.
I want a way to find a partiular name in the array and increase it's value by 1 (or by any other integer number).
So in my example:
foreach ($my_array as $my_name=>$my_number)
{
// loop to find $my_name - easily done
// increase $my_number by 1 inside the array
// so in the next loop i will have the increased value
// no idea how to do this so far
}
Is there a build-in function in php or i write something of my own?
$my_array[$my_name]++;
Expanding on that, here is an even easier way to do the same thing. Here, no loop is needed. I assume you have your search value already in a var. Simply change $search to your var name.
if ( array_key_exists( $search, $my_array ) ) {$my_array[$search]++;}