function checkProductsGlobalVariable($con) { global $products; if (empty($products)) { $products = fetch_products_toArray($con); } return $products; }
function calculate_product_quantity($con) { global $nodes; global $products; $products = fetch_products_toArray($con); //reset the global quantity for ($i = 0; $i < sizeof($products) - 1; $i++) { $products[$i]['global_quantity'] = 0; } //calculate the global quantity for each product for ($i = 0; $i < sizeof($nodes) - 1; $i++) { for ($j = 0; $j < sizeof($products) - 1; $j++) { if ($products[$j]['name'] == $nodes[$i]['serves']) { $products[$j]['global_quantity'] += $nodes[$i]['quantity']; } } } //calculate the base_cost for ($i = 0; $i < sizeof($products); $i++) { if ($products[$i]['global_quantity'] == 0) { $products[$i]['base_cost'] = $products[$i]['max_cost']; } else { $products[$i]['base_cost'] = $products[$i]['max_cost'] / $products[$i]['global_quantity']; } } }