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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help comparing arrays

Status
Not open for further replies.

8ginga8

Programmer
Dec 14, 2004
54
CA
Hi,
I hope that some one can help me, I am new at PHP and I am trying to take the results from 2 querys and return the difference and maybe even take it a bit further. Here is an example.

array 1:
toplevel 1111
part QTY
a 1
b 1
c 6

array 2:
toplevel 2222
part QTY
a 4
c 2
e 2

what I want is this output
Output:
the toplevel 1111 different from toplevel 2222
part QTY
a -3
b 1
c 4
e 2
 
You could try this

$array3 = array()
foreach($array1 as $part=>$QTY)
{
$array3[$part] = $QTY-$array2[$part];
}

Ok in this example we loop though each element in the first array. Then we take its value and subtract it from $array2, and then store it in $array3.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top