我有以下简单字典,我想要纬度数组,当状态1存储一个数组,状态2存储第二个数组 请帮帮我
data = (
{
created = "2017-11-13 09:04:18";
"end_date" = "2017-11-13 11:49:08";
id = 878;
latitude = "23.032190322875977000";
longitude = "72.565238952636720000";
status = 1;
"user_id" = 21;
},
{
created = "2017-11-13 11:49:08";
"end_date" = "2017-11-13 13:13:15";
id = 888;
latitude = "23.032133102416992000";
longitude = "72.565208435058600000";
status = 1;
"user_id" = 21;
},
{
created = "2017-11-13 13:13:15";
"end_date" = "2017-11-13 13:26:26";
id = 891;
latitude = "23.032199859619140000";
longitude = "72.565269470214840000";
status = 2;
"user_id" = 21;
},
{
created = "2017-11-13 13:26:26";
"end_date" = "2017-11-13 16:54:20";
id = 892;
latitude = "23.032056808471680000";
longitude = "72.565223693847660000";
status = 2;
"user_id" = 21;
}
)
答案 0 :(得分:3)
使用filter
和map
:
let statusOne = data.filter({ $0.status == 1 }).map({ $0.latitude })
let statusTwo = data.filter({ $0.status == 2 }).map({ $0.latitude })
答案 1 :(得分:2)
请尝试下面的代码:它在swift 3中:
let lattitude1Array = NSMutableArray()
let lattitude2Array = NSMutableArray()
for record in data {
if let status = record["status"] as? Int {
if status == 1 {
lattitude1Array.add(record["lattitude"])
} else {
lattitude2Array.add(record["lattitude"])
}
}
}
答案 2 :(得分:1)
简单代码使用此
if (isset($_POST['submit1'])) {
$mediname = pg_escape_string($_POST['medname']);
$tits = pg_escape_string($_POST['quantity']);
$quirt = ("UPDATE medicine_invent set med_stock = med_stock - $tits where med_name = $mediname");
$sq = pg_query($quirt);
}
答案 3 :(得分:0)
使用以下代码行
localize=True
希望能帮助你:)