我面临的问题似乎无法理解.
我有这个代码在iOS 7的Xcode 5中完美运行:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
NSString* embedHTML = @"\
<html><head><meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; user-scalable=0;\"/>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: black;\
}\
</style>\
</head><body style=\"margin:0;\">\
<embed id=\"yt\" src=\"https://www.youtube.com/v/M7lc1UVf-VE?hd=1\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, width, height];
[webview loadHTMLString:html baseURL:nil];
[self.view addSubview:webview]; …
Run Code Online (Sandbox Code Playgroud) 我找到了一些我无法解释的东西,也许这里有人可以给我一些提示.
我有以下测试代码,它打印2个格式化的时间戳,一个用于31.03.2013,一个用于31.03.2014,使用date()
和gmdate()
:
<?php
function print_date($timestamp, $year) {
// Add timezone offset for germany
$timestamp += 3600;
print "in $year\n";
print "date: " . date('d.m.Y H:i:s', $timestamp) . "\n";
print "gmdate: " . gmdate('d.m.Y H:i:s', $timestamp) . "\n";
print "\n";
}
$end_2013 = 1364684400; // 31.03.2013
$end_2014 = 1396216800; // 31.03.2014
print_date($end_2013, '2013');
print_date($end_2014, '2014');
print "Default timezone: " . date_default_timezone_get() . "\n";
Run Code Online (Sandbox Code Playgroud)
结果让我感到惊讶:
in 2013
date: 31.03.2013 01:00:00
gmdate: 31.03.2013 00:00:00
in 2014
date: 31.03.2014 01:00:00 …
Run Code Online (Sandbox Code Playgroud) 我真的是PHP新手,需要有关数组搜索的建议。
如果要搜索多维数组中的元素,可以使用array_filter
,也可以遍历该数组并查看是否存在符合我的条件的元素。
我在很多地方都看到了这两个建议。哪个更快?下面是一个示例数组。
Array (
[0] => Array (
[id] => 4e288306a74848.46724799
[question] => Which city is capital of New York?
[answers] => Array (
[0] => Array (
[id] => 4e288b637072c6.27436568
[answer] => New York
[question_id_fk] => 4e288306a74848.46724799
[correct] => 0
)
[1] => Array (
[id] => 4e288b63709a24.35955656
[answer] => Albany
[question_id_fk] => 4e288306a74848.46724799
[correct] => 1
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
我正在这样搜索。
$thisQuestion = array_filter($pollQuestions, function($q) {
return questionId == $q["id"];
});
Run Code Online (Sandbox Code Playgroud)