我在concerete5上的现有包中添加了一些额外的功能。我的php数组有些问题。我似乎无法想出创建数组的代码,此时我是每个对象的完整变量列表。这是繁重的代码,使用数组会更好。
任何人都可以帮我创建正确的数组吗?
$dates_ak = CollectionAttributeKey::getByHandle('event_multidate');
$dates_akID = $dates_ak->akID;
$dates = $_POST['akID'][$dates_akID];
$date_count = count($dates);
$dates = $_REQUEST['akID'][$dates_akID];
$dates_renumber = array();
foreach($dates as $date_item){
array_push($dates_renumber, $date_item);
}
$start_date = date('Y-m-d',strtotime($dates_renumber[1]['value_st_dt']));
/* GET MULTI DATE DATA */
$start_date1 = date('l d M Y',strtotime($dates_renumber[1]['value_st_dt']));
$value_st_h1 = ($dates_renumber[1]['value_st_h']);
$value_st_m1 = ($dates_renumber[1]['value_st_m']);
$value_st_a1 = ($dates_renumber[1]['value_st_a']);
$value_end_h1 = ($dates_renumber[1]['value_end_h']);
$value_end_m1 = ($dates_renumber[1]['value_end_m']);
$value_end_a1 = ($dates_renumber[1]['value_end_a']);
$start_date2 = date('l d M Y',strtotime($dates_renumber[2]['value_st_dt']));
$value_st_h2 = ($dates_renumber[2]['value_st_h']);
$value_st_m2 = ($dates_renumber[2]['value_st_m']);
$value_st_a2 = ($dates_renumber[2]['value_st_a']);
$value_end_h2 = ($dates_renumber[2]['value_end_h']);
$value_end_m2 = ($dates_renumber[2]['value_end_m']);
$value_end_a2 = ($dates_renumber[2]['value_end_a']);
$start_date3 = date('l d M Y',strtotime($dates_renumber[3]['value_st_dt']));
$value_st_h3 = ($dates_renumber[3]['value_st_h']);
$value_st_m3 = ($dates_renumber[3]['value_st_m']);
$value_st_a3 = ($dates_renumber[3]['value_st_a']);
$value_end_h3 = ($dates_renumber[3]['value_end_h']);
$value_end_m3 = ($dates_renumber[3]['value_end_m']);
$value_end_a3 = ($dates_renumber[3]['value_end_a']);
$start_date4 = date('l d M Y',strtotime($dates_renumber[4]['value_st_dt']));
$value_st_h4 = ($dates_renumber[4]['value_st_h']);
$value_st_m4 = ($dates_renumber[4]['value_st_m']);
$value_st_a4 = ($dates_renumber[4]['value_st_a']);
$value_end_h4 = ($dates_renumber[4]['value_end_h']);
$value_end_m4 = ($dates_renumber[4]['value_end_m']);
$value_end_a4 = ($dates_renumber[4]['value_end_a']);
$start_date5 = date('l d M Y',strtotime($dates_renumber[5]['value_st_dt']));
$value_st_h5 = ($dates_renumber[5]['value_st_h']);
$value_st_m5 = ($dates_renumber[5]['value_st_m']);
$value_st_a5 = ($dates_renumber[5]['value_st_a']);
$value_end_h5 = ($dates_renumber[5]['value_end_h']);
$value_end_m5 = ($dates_renumber[5]['value_end_m']);
$value_end_a5 = ($dates_renumber[5]['value_end_a']);
$start_date6 = date('l d M Y',strtotime($dates_renumber[6]['value_st_dt']));
$value_st_h6 = ($dates_renumber[6]['value_st_h']);
$value_st_m6 = ($dates_renumber[6]['value_st_m']);
$value_st_a6 = ($dates_renumber[6]['value_st_a']);
$value_end_h6 = ($dates_renumber[6]['value_end_h']);
$value_end_m6 = ($dates_renumber[6]['value_end_m']);
$value_end_a6 = ($dates_renumber[6]['value_end_a']);
$start_date7 = date('l d M Y',strtotime($dates_renumber[7]['value_st_dt']));
$value_st_h7 = ($dates_renumber[7]['value_st_h']);
$value_st_m7 = ($dates_renumber[7]['value_st_m']);
$value_st_a7 = ($dates_renumber[7]['value_st_a']);
$value_end_h7 = ($dates_renumber[7]['value_end_h']);
$value_end_m7 = ($dates_renumber[7]['value_end_m']);
$value_end_a7 = ($dates_renumber[7]['value_end_a']);
$start_date8 = date('l d M Y',strtotime($dates_renumber[8]['value_st_dt']));
$value_st_h8 = ($dates_renumber[8]['value_st_h']);
$value_st_m8 = ($dates_renumber[8]['value_st_m']);
$value_st_a8 = ($dates_renumber[8]['value_st_a']);
$value_end_h8 = ($dates_renumber[8]['value_end_h']);
$value_end_m8 = ($dates_renumber[8]['value_end_m']);
$value_end_a8 = ($dates_renumber[8]['value_end_a']);
$start_date9 = date('l d M Y',strtotime($dates_renumber[9]['value_st_dt']));
$value_st_h9 = ($dates_renumber[9]['value_st_h']);
$value_st_m9 = ($dates_renumber[9]['value_st_m']);
$value_st_a9 = ($dates_renumber[9]['value_st_a']);
$value_end_h9 = ($dates_renumber[9]['value_end_h']);
$value_end_m9 = ($dates_renumber[9]['value_end_m']);
$value_end_a9 = ($dates_renumber[9]['value_end_a']);
$start_date10 = date('l d M Y',strtotime($dates_renumber[10]['value_st_dt']));
$value_st_h10 = ($dates_renumber[10]['value_st_h']);
$value_st_m10 = ($dates_renumber[10]['value_st_m']);
$value_st_a10 = ($dates_renumber[10]['value_st_a']);
$value_end_h10 = ($dates_renumber[10]['value_end_h']);
$value_end_m10 = ($dates_renumber[10]['value_end_m']);
$value_end_a10 = ($dates_renumber[10]['value_end_a']);
/* Create variable for each date */
if ($start_date1 != 'Thursday 01 Jan 1970') { $date1 = $start_date1.' '.$value_st_h1.':'.$value_st_m1.' '.$value_st_a1.' - '.$value_end_h1.':'.$value_end_m1.' '.$value_end_a1.'<br/>'; }
if ($start_date2 != 'Thursday 01 Jan 1970') { $date2 = $start_date2.' '.$value_st_h2.':'.$value_st_m2.' '.$value_st_a2.' - '.$value_end_h2.':'.$value_end_m2.' '.$value_end_a2.'<br/>'; }
if ($start_date3 != 'Thursday 01 Jan 1970') { $date3 = $start_date3.' '.$value_st_h3.':'.$value_st_m3.' '.$value_st_a3.' - '.$value_end_h3.':'.$value_end_m3.' '.$value_end_a3.'<br/>'; }
if ($start_date4 != 'Thursday 01 Jan 1970') { $date4 = $start_date4.' '.$value_st_h4.':'.$value_st_m4.' '.$value_st_a4.' - '.$value_end_h4.':'.$value_end_m4.' '.$value_end_a4.'<br/>'; }
if ($start_date5 != 'Thursday 01 Jan 1970') { $date5 = $start_date5.' '.$value_st_h5.':'.$value_st_m5.' '.$value_st_a5.' - '.$value_end_h5.':'.$value_end_m5.' '.$value_end_a5.'<br/>'; }
if ($start_date6 != 'Thursday 01 Jan 1970') { $date6 = $start_date6.' '.$value_st_h6.':'.$value_st_m6.' '.$value_st_a6.' - '.$value_end_h6.':'.$value_end_m6.' '.$value_end_a6.'<br/>'; }
if ($start_date7 != 'Thursday 01 Jan 1970') { $date7 = $start_date7.' '.$value_st_h7.':'.$value_st_m7.' '.$value_st_a7.' - '.$value_end_h7.':'.$value_end_m7.' '.$value_end_a7.'<br/>'; }
if ($start_date8 != 'Thursday 01 Jan 1970') { $date8 = $start_date8.' '.$value_st_h8.':'.$value_st_m8.' '.$value_st_a8.' - '.$value_end_h8.':'.$value_end_m8.' '.$value_end_a8.'<br/>'; }
if ($start_date9 != 'Thursday 01 Jan 1970') { $date9 = $start_date9.' '.$value_st_h9.':'.$value_st_m9.' '.$value_st_a9.' - '.$value_end_h9.':'.$value_end_m9.' '.$value_end_a9.'<br/>'; }
if ($start_date10 != 'Thursday 01 Jan 1970') { $date10 = $start_date10.' '.$value_st_h10.':'.$value_st_m10.' '.$value_st_a10.' - '.$value_end_h10.':'.$value_end_m10.' '.$value_end_a10.'<br/>'; }
/* Echo event somewhere else */
echo $date1.$date2.$date3.$date4.$date5.$date6.$date7.$date8.$date9.$date10;
答案 0 :(得分:0)
我改变了foreach
$eventDates = '';
foreach(array_slice($dates,1) as $date_item) {
$start_date = date('l jS M Y',strtotime($date_item['value_st_dt']));
$eventDates .= $start_date.' '.$date_item['value_st_h'].':'.$date_item['value_st_m'].' '.$date_item['value_st_a'].' - '.$date_item['value_end_h'].':'.$date_item['value_end_m'].' '.$date_item['value_end_a'].'<br/>';
}
echo $eventDates;