-2

细绳:[Name] => google [AF] => 0 [AX] => 2 [AL] => 1 [DZ] => 0 .....

输出:

[AX,2]
[AL,1]

具有 [0] 个条目的国家/地区将被排除在列表中

I have tried using sql but  i want for php
Select '[AF,' + LTrim(Cast(Sum(AF) as varChar(5))) + ']' 
From Table Where name = 'Andy'
Union
Select '[AS,' + LTrim(Cast(Sum(AS) as varChar(5))) + ']' 
From Table Where name = 'Andy'
Union
Select '[AQ,' + LTrim(Cast(Sum(AQ) as varChar(5))) + ']' 
From Table Where name = 'Andy'

还有 http://sqlfiddle.com/#!2/42756/5

但我需要在 php

4

1 回答 1

0

一个简单的 foreach 循环就可以解决问题:

foreach($array AS $key=>$value){
   if($value!=0){
       echo "$key,$value";
   }
}
于 2013-09-06T13:31:03.823 回答