我有一个看起来像的数组 –
Array ( [0] => stdClass Object ( [post_date] => 2017-01-04 14:28:00 ) [1] => stdClass Object ( [post_date] => 2017-01-05 11:06:00 ) [2] => stdClass Object ( [post_date] => 2017-02-04 14:28:00 ) [3] => stdClass Object ( [post_date] => 2017-02-04 14:34:00 ) )
foreach($unique_dates as $val) { $year=substr($val->post_date,4); $month=substr($val->post_date,5,2); $monthName = date('F',mktime(0,$month,10)); echo $monthName." ".$year."<br>"; }
January 2017 January 2017 February 2017 February 2017
但是我希望输出像 –
January 2017 February 2017
我尝试如下但没有得到适当的输出 –
$unique_dates = array_map( 'unserialize',array_unique( array_map( 'serialize',$dates ) ) );
我想删除重复值.
这怎么可能?
谢谢.
解决方法
像这样运行:
foreach($unique_dates as $val) { $year=substr($val->post_date,10)); $result[] = $monthName." ".$year; } $result = array_flip($result); // here will remove the duplicate value,and return as the keys of the array. array_walk($results,function($v,$k){echo $k.'<br>';});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。