这是我的代码
while ($itog = mysql_fetch_array($result, MYSQL_ASSOC))
{
$week=$itog["week"];
if( $week <= 7 ){
if($todayweek == $week){
$itog["today"] = $todaydate ;
}
}
if($week == 8){
$startdate =$itog["startdate"] ;
if ($startdate == $todaydate){
$itog["today"] = $todaydate ;
}
}
if($week == 9){
$startdate =$itog["startdate"] ;
$enddate =$itog["enddate"] ;
if( $startdate <= $todaydate && $todaydate <= $enddate){
$itog["today"] = $todaydate ;
}
}
$massiv[] = $itog;
}
这就是结果:
{ id:“7”, imgsrc:“”, 纳兹夫:“Клвав”, 周:“8”, startdate:“2015-01-25”, enddate:“0000-00-00” }
{ id:“8”, imgsrc:“”, 纳兹夫:“Пятыйдень”, 周:“5”, startdate:“2015-01-04”, 结束日期:“2015-04-18” }
{ id:“9”, imgsrc:“”, 纳兹夫:“ТупойТекуще”, 周:“9”, startdate:“2015-01-20”, enddate:“2015-02-01”, 今天:“2015-01-26” }
你可以看到只有数组的最后一个元素有TODAY参数...我怎样才能创建一个只包含元素的新数组?
答案 0 :(得分:0)
好的,所以你可以做这样的事情来获得只有具有今天参数的元素:
这应该在while()
循环
$newArray = array();
foreach ($massiv as $ma) {
if (array_key_exist('today', $ma)) {
$newArray[] = $ma;
}
}