MySQL查询后使用PHP输出唯一数据

I'm trying to output to a page a unique set of data based on a MySQL query. The final result should include ONE pharmacy and the associated price. Here's a sample of the array created by the query and while loop:

Array ( 
     [0] => Array ( 
         [Copay_Amount] => 18.37 
         [Pharmacy_Name] => CVS PHARMACY 04286 
     ) 
     [1] => Array ( 
         [Copay_Amount] => 27.54 
         [Pharmacy_Name] => HEB PHARMACY 662 
     ) 
     [2] => Array ( 
         [Copay_Amount] => 22.46 
         [Pharmacy_Name] => WALMART PHARMACY 10-4194 104194 
     ) 
     [3] => Array ( 
         [Copay_Amount] => 9.77 
         [Pharmacy_Name] => PUBLIX PHARMACY 0050 
     ) 
     [4] => Array ( 
         [Copay_Amount] => 18.37 
         [Pharmacy_Name] => CVS PHARMACY 06961 
     ) 
     [5] => Array ( 
         [Copay_Amount] => 12.52 
         [Pharmacy_Name] => KROGER PHARMACY 24660 
     ) 
     [6] => Array ( 
         [Copay_Amount] => 22.46 
         [Pharmacy_Name] => WALMART PHARMACY 10-1187 101187 
     ) 

This produces the following

<table class="table table-striped .table-responsive h3">  
  <tbody>
    <tr>
     <td>CVS</td>
     <td>$18.37</td>
    </tr>
    <tr>
     <td>HEB</td>
     <td>$27.54</td>
    </tr>
    <tr>
     <td>WALMART</td>
     <td>$22.46</td>
    </tr>
    <tr>
     <td>PUBLIX</td>
     <td>$9.77</td>
    </tr>
    <tr>
     <td>CVS</td>
     <td>$18.37</td>
    </tr>
    <tr>
     <td>KROGER</td>
     <td>$12.52</td>
    </tr>
    <tr>
     <td>WALMART</td>
     <td>$22.46</td>
    </tr>
    <tr>
     <td>PUBLIX</td>
     <td>$9.77</td>
    </tr>
    <tr>
     <td>PLAQUEMINES</td>
     <td>$12.35</td>
    </tr>
    <tr>
     <td>BARTELL DRUGS</td>
     <td>$12.17</td>
    </tr>
    <tr>
     <td>BROOKSHIRES</td>
     <td>$12.68</td>
    </tr>
    <tr>
     <td>KROGER  </td>
     <td>$12.52</td>
    </tr>
    <tr>
     <td>WALMART</td>
     <td>$22.46</td>
    </tbody>
   </table>

I clean the pharmacy store IDs off in the while loop which looks like this:

$cashprice = round($row['Copay_Amount'],2);
$pharmacy = trim($row['Pharmacy_Name']);
$pharmacy = substr($pharmacy, 0, strpos($pharmacy, "#"));
$pharmacy = str_replace('DISCOUNT',"",$pharmacy); 
$pharmacy = str_replace('PHARMACY',"",$pharmacy);
$pharmacy = preg_replace('/[-#()0-9]+/', '', $pharmacy);

I'm trying to remove the duplicates from the table, in this case from CVS, Walmart, and Publix so it is just showing one unique pharmacy and price set. I've tried to do this at the MySQL level using GROUP BY but to do that I need a second table that matches the long pharmacy name with the shorter one and the query time is unacceptable. I also have just experimented with array_unique as partly shown here:

$items = array_unique($r->fetch_assoc(), SORT_NUMERIC);

but that removes all but the CVS items and then those repeat four times (the array above is only a partial...the MySQL query set LIMIT 0, 100).

Hoping to find someone to take pity on me and my peculiar PHP ways to help me through this! Thanks!

</div>

I ended up using the brute force method. After I backed up the database I performed UPDATES on the major pharmacy fields; once you get through the top 10 that covers about 80% of all of them which is good enough. Dangerous? You bet. Recommended? Eh eh, but I did many tests locally first and then on my production db.

I'm now looking at how I can normalize the database so that I can add fields like this as needed in the future. Having the short_pharmacy field in the same db dramatically sped up the query not to mention bringing back the benefits found in using GROUP BY.

Thanks!