PHP:从数组中获取时间戳数据
这里的一个 php 学生现在已经被困了好几个小时了:(
这是我的问题,这个:
echo"<pre>";print_r($array1);echo"</pre>";
prints:
Array
(
[0] => stdClass Object
(
[id] => 4d6f6aec35993704d52c0d9d
[createdAt] => 1299147500
[place] => stdClass Object
(
[id] => 4adcda40f964a5208a3e21e3
)
)
[1] => stdClass Object
(
[id] => 654jk654n646g54j6kl54j645
[createdAt] => 1299147500
[place] => stdClass Object
(
[id] => 4gh543gh5h5g354h3gg53gh
)
)
.
.
.
createdAt 是该地方创建日期的时间戳。 我需要在时间戳之间创建的地点的地点 ID。
这是我对时间戳之间逻辑的方法:
$array2 = array();
$begin = strtotime("2011-02-17 12:22:49");
$end = strtotime("2011-03-03 10:00:00");
foreach($array1 as $timestamp){
if($timestamp <= $end && $timestamp >= $begin){
$array2[] = $timestamp;
}
}
这对我来说是正确的,但正如我所说,我在 $array2 中需要的信息是在这些时间戳之间创建的位置 id。
我怎样才能做到这一点?
非常感谢!
A php student here that has been stuck for many hours now :(
Here's my problem, this:
echo"<pre>";print_r($array1);echo"</pre>";
prints:
Array
(
[0] => stdClass Object
(
[id] => 4d6f6aec35993704d52c0d9d
[createdAt] => 1299147500
[place] => stdClass Object
(
[id] => 4adcda40f964a5208a3e21e3
)
)
[1] => stdClass Object
(
[id] => 654jk654n646g54j6kl54j645
[createdAt] => 1299147500
[place] => stdClass Object
(
[id] => 4gh543gh5h5g354h3gg53gh
)
)
.
.
.
createdAt is the timestamp of the date the place was created.
I need the place id of the places created in between timestamps.
Here's my approach on the in between timestamps logic:
$array2 = array();
$begin = strtotime("2011-02-17 12:22:49");
$end = strtotime("2011-03-03 10:00:00");
foreach($array1 as $timestamp){
if($timestamp <= $end && $timestamp >= $begin){
$array2[] = $timestamp;
}
}
It is correct to me, but as I said the info I need in $array2 is the place ids created in between these timestamps.
How can I do that?
Thanks a ton!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是想在这里变得聪明......;-)
Just trying to be clever here... ;-)
对于 PHP >= 5.3 中的闭包来说,这将是一个很好的用例:
本质上它与 deceze,但我们使用较新的闭包代替旧式匿名函数从 PHP 5.3 开始。
This would be a nice use-case for closures in PHP >= 5.3:
Essentially it's the same code as shown by deceze, but instead of the old-style anonymous functions we use the newer closures from PHP 5.3.
如果我正确理解这个问题,我想你会想要这样做。
另外,为了让您知道您可以这样做:
在调试时节省一些击键次数。
I think you want to do this if I understand the question correctly.
Also just so you know you can do:
to save your self some key strokes when debugging.