Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>php script</p> <pre><code>&lt;pre&gt; &lt;?php // Data Source $db_data = array( array('manufacturers_id' =&gt; 1, 'manufacturers_name' =&gt; 'Some Company', 'products_price' =&gt; 1.99, 'products_quantity' =&gt; 12, 'products_cost' =&gt; 0.49), array('manufacturers_id' =&gt; 1, 'manufacturers_name' =&gt; 'Some Company', 'products_price' =&gt; 1.99, 'products_quantity' =&gt; 12, 'products_cost' =&gt; 0.49), array('manufacturers_id' =&gt; 2, 'manufacturers_name' =&gt; 'Another Company', 'products_price' =&gt; 12.99, 'products_quantity' =&gt; 112, 'products_cost' =&gt; 10.49), array('manufacturers_id' =&gt; 2, 'manufacturers_name' =&gt; 'Another Company', 'products_price' =&gt; 12.99, 'products_quantity' =&gt; 112, 'products_cost' =&gt; 10.49), ); // Sort Data $db_data_sorted = array(); foreach ($db_data as $data) { $db_data_sorted[$data['manufacturers_id']][$data['manufacturers_name']]['brands_total_sales'] += (intval($data['products_quantity']) * floatval($data['products_price'])); $db_data_sorted[$data['manufacturers_id']][$data['manufacturers_name']]['products'][] = array( 'products_price' =&gt; $data['products_price'], 'products_quantity' =&gt; $data['products_quantity'], 'products_cost' =&gt; $data['products_cost'] ); } // Debug print_r($db_data_sorted); ?&gt; </code></pre> <p>output:</p> <pre><code>Array ( [1] =&gt; Array ( [Some Company] =&gt; Array ( [brands_total_sales] =&gt; 47.76 [products] =&gt; Array ( [0] =&gt; Array ( [products_price] =&gt; 1.99 [products_quantity] =&gt; 12 [products_cost] =&gt; 0.49 ) [1] =&gt; Array ( [products_price] =&gt; 1.99 [products_quantity] =&gt; 12 [products_cost] =&gt; 0.49 ) ) ) ) [2] =&gt; Array ( [Another Company] =&gt; Array ( [brands_total_sales] =&gt; 2909.76 [products] =&gt; Array ( [0] =&gt; Array ( [products_price] =&gt; 12.99 [products_quantity] =&gt; 112 [products_cost] =&gt; 10.49 ) [1] =&gt; Array ( [products_price] =&gt; 12.99 [products_quantity] =&gt; 112 [products_cost] =&gt; 10.49 ) ) ) ) ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload