如何添加空字符串作为现有数组的第一个元素?

时间:2017-07-29 08:56:13

标签: php arrays array-merge

我正在合并数组值。这是我的代码,它工作正常。

else

enter image description here

现在我想在数组的第一个位置添加另一个包含空字符串的元素,并将x作为最后一个元素。我希望第一个下拉选项为空。

3 个答案:

答案 0 :(得分:3)

尝试使用 array_unshift() php函数检查here 像这样

   $queue=array_merge($image_sizes, array(
        'full',
       ) );
    array_unshift($queue, " ");
    return $queue;

答案 1 :(得分:0)

您可以使用array_unshift,也可以像对待full一样进行合并:

function photomag_image_size() {
    $image_sizes = get_intermediate_image_sizes();
    $image_sizes = array_merge(array(""), $image_sizes);
    return array_merge($image_sizes, array('full') ); 
}

答案 2 :(得分:0)

再次使用$temp = array_merge($image_sizes, array('full')); return array_merge(array("first") , $temp);

-(void)fireNotificationonDate:(NSDate *)dateEnter onTime:(NSString *)strTime
{
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *timeComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:dateEnter];
   [timeComponents setHour:[strTime integerValue]];
   [timeComponents setMinute:00];
   [timeComponents setSecond:0];
   [timeComponents setYear:[timeComponents year]];
   [timeComponents setMonth:[timeComponents month]];
   [timeComponents setDay:[timeComponents day]];
   NSDate *dtFinal = [calendar dateFromComponents:timeComponents];
   NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
   [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];

   NSString *fierDate = [formatter stringFromDate:dtFinal];
   NSLog(@"%@",fierDate);

   UILocalNotification *notification = [[UILocalNotification alloc] init];
   notification.fireDate = dtFinal;
   notification.alertBody = @"";
   notification.timeZone = [NSTimeZone defaultTimeZone];
   notification.soundName = UILocalNotificationDefaultSoundName;
   notification.applicationIconBadgeNumber = 1;

   [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}