Re: Simple array problem

From: Date: Tue, 01 Jul 2008 12:42:47 +0000
Subject: Re: Simple array problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-276162@lists.php.net to get a copy of this message
At 9:35 AM +0100 7/1/08, Richard Heyes wrote:
Brian Dunning wrote:
Seems like it should be really simple but all the ways I can figure out to do it are too kludgey.
It's rather easy: for ($i=0; $i<count($arr); $i++) {
    if ($arr[$i][0] == $new_array[0]) {
        $arr[$i][1] += $new_array[1];
        break; // Optional - means the first "orange" found will be
               // updated only
    }
} -- Richard Heyes
Small correction: for ($i=0; $i<count($arr); $i++) {
    if ($arr[$i][0] == $new_value [0])
      {
        $arr[$i][1] += $new_value [1];
        break; // Optional - means the first "orange" found will be
               // updated only
       }
} See here: http://www.webbytedd.com/b1/array/ But, I'm not sure as to why you (Brian) would want to do that anyway. tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#276162) next »