Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associative array question

Status
Not open for further replies.

richardko

Programmer
Jun 20, 2006
127
US
i have an array that looks like this:
Array(
Array
(
[warehouse] => OTHER
[location] => B11
[skuonbox] => hx252
[caseqty] => 8
[row] =>
[shelving] => 30
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] => OTHER
[location] => B12
[skuonbox] => hx252
[caseqty] => 8
[row] =>
[shelving] => 30
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] => OTHER
[location] => C23
[skuonbox] => 423901-1691a
[caseqty] => 6
[row] =>
[shelving] => 36
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] => OTHER
[location] => C24
[skuonbox] => 423901-1691a
[caseqty] => 6
[row] =>
[shelving] => 36
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] => OTHER
[location] => D23
[skuonbox] => 423901-1691a
[caseqty] => 6
[row] =>
[shelving] => 36
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] => OTHER
[location] => D24
[skuonbox] => 423901-1691a
[caseqty] => 6
[row] =>
[shelving] => 36
[shelf] =>
[count] =>
[cases] => 0
[overstockqty] => 0
)
Array
(
[warehouse] =>
[location] =>
[skuonbox] =>
[caseqty] => 0
[row] =>
[shelving] => 0
[shelf] =>
[count] => 0
[cases] => 0
[overstockqty] => 0
)
)
I need to multiply "caseqty" with "cases" and add all the arrays. Is there a function to do this without reiterating through the array?
 
Yes and no.

There will always have to be a iteration of the elements of the array. It's just a matter of whether you explicitly perform the iteration using a foreach() loop or whether you you do the iteration implicitly using something like array_walk().


Want the best answers? Ask the best questions! TANSTAAFL!
 
if you are building the array from a db query, why don't you do the multiplication and summing as part of the array set up?
 
Thanks for the responses. I will have to close this thread for now. But I will keep the responses in mind :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top