I have two arrays that derive from a MYSQL database, each table with an identical structure:
Table1
+key1
-field1
Table2
+key2
-field2
Where the keys of these two tables coincide, I'm trying to subtract field2 from field 1. Here is what I have so far:
$sql1 = "SELECT key1, field1 FROM table1";
$query1 = @mysql_query($sql1);
$row1 = @mysql_fetch_array($query1);
$sql2 = "SELECT key2, field2 FROM table2";
$query2 = @mysql_query($sql2);
$row2 = @mysql_fetch_array($query2);
$array1 = $row1;
$array2 = $row2;
foreach($array1 AS $key => $val)
{
$newArray[] = $val - $array2[$key];
}
The difference is supposed to be stored in $newArray.
How can I specify that I am trying to obtain the difference between field1 and field2?