我有一个数组.my数组存储在
$details = $this->api_model->testw();
这里的mysql查询返回结果数组$details
。
现在我想保留第一个索引datetime值和最后一个索引datetime值
喜欢
$first='2010-05-15 11:29:45';
$last='2010-05-26 16:04:24';
我的数组
Array
(
[0] => Array
(
[id] => 2
[type] => comment
[text] => hey
[datetime] => 2010-05-15 11:29:45
)
[1] => Array
(
[id] => 3
[type] => status
[text] => oi
[datetime] => 2010-05-26 15:59:53
)
[2] => Array
(
[id] => 4
[type] => status
[text] => yeww
[datetime] => 2010-05-26 16:04:24
)
)
使用end()
和reset()
获取第一个和最后一个数组,然后访问datetime
值,如下所示:
// Get the first and last sub-arrays
$first = reset($data);
$last = end($data);
// Create an array containing the datetimes
$result = array($first['datetime'], $last['datetime']);
// Output the contents of the above array
print_r($result);
输出:
Array
(
[0] => 2010-05-15 11:29:45
[1] => 2010-05-26 16:04:24
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句