lua的table.sort
local aa = {{a=11},{a=44},{a=33},{a=2} }
table.sort(aa,function(a,b)
return a.a>b.a
end)
for k, v in pairs(aa[1]) do
ngx.say(k)
ngx.say(v)
end
for k, v in pairs(aa[2]) do
ngx.say(k)
ngx.say(v)
end
for k, v in pairs(aa[3]) do
ngx.say(k)
ngx.say(v)
end
for k, v in pairs(aa[4]) do
ngx.say(k)
ngx.say(v)
end
结果:
a
44
a
33
a
11
a
2