You are here: Re: combine array of array « PHP Programming Language « IT news, forums, messages
Re: combine array of array

Posted by Good Man on 07/12/07 19:02

cc96ai <calvin.chan.cch@gmail.com> wrote in news:1184259772.981520.203770
@n60g2000hse.googlegroups.com:

> $array1 = array(
> array(
> "product_id" => 3,
> "SKU" => "AES46",
> "qty" => 3,
> ),
> );
>
> $array2 = array(
> array(
> "product_id" => 3,
> "SKU" => "AES46",
> "qty" => 2,
> ),
> array(
> "product_id" => 4,
> "SKU" => "AES47",
> "qty" => 3,
> ),
> );
> I want to add up the qty of two array if the product_id is same
> I try on $array1 + $array2, but which is not I want,
>
> I only have to use 2 foreach loop in my mind
> foreach ($array1 ...)
> foreach ($array2 ...)
> if ( id same )
>
> Have other better suggestion or PHP function for this ?
> I am using PHP 4.4

I don't quite follow you, but this might help:

http://www.php.net/array_diff
- computes the difference of arrays (this gives you an array of values that
AREN'T the same between them, perhaps with this info you can figure out
which ones ARE the same)

http://www.php.net/manual/en/function.array-unique.php
- removes duplicate values from an array


Good luck

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация