我有下面的代码段
func getDeviceUUID() -> String {
guard let uuid = UIDevice.current.identifierForVendor?.uuidString else {
assertionFailure("Nil while unwrapping UIDevice.current.identifierForVendor?.uuidString")
return ""}
return uuid
}
print(getDeviceUUID()) //50E6548C-0BB4-4979-8F5F-DFAD422BEB26
如何制作 foreach ($response as $sms) {
$receiver = "(".$sms['from'].",\"".$sms['body']."\",".$sms['timestamp'].")";
$res .=$receiver.",";
}
$res = substr($res, 0, -1);
- 变量并在此代码之外使用它?
由于
答案 0 :(得分:0)
您可以在循环外创建一个数组,并从循环中将每个$sms['from']
推送到该数组。循环完成后,它将包含所有项目。
$sms_from = [];
foreach ($response as $sms) {
$sms_from[] = $sms['from'];
$receiver = "
(".$sms['from'].",\"".$sms['body']."\",".$sms['timestamp'].")";
$res .=$receiver.",";
}
$res = substr($res, 0, -1);
var_dump($sms_from);// contains all the $sms['from']