Re: Simple array problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux