-
PHP数组去重的方法
?php$arr=array(1,1,2,3,3,3,4,4,5,6,6,7,8,8,9,9,9);$arr=array_unique($arr);//去重$arr=array_values($arr);//排序print_r($arr);//输出去重后的数组? …
-
PHP中使用正则表达式来检测字符中是否含有大写字母
使用preg_match()函数配合正则表达式来检测是否含有大写字母 preg_match 函数用于执行一个正则表达式pattern匹配,会返回 pattern 的匹配次数(0或1)。0代表没有匹配,1代表有匹配。 用到的正则为:/[A-Z]/,用于查找大写字母 ?phpfunctionis_bigstr($str){if(preg_match(/[A-Z]/,$str)){echo有大写字母!br;}else{echo没有大写字母!br;}}is_bigstr(hello);is_bigstr(Hello);? …
-
PHP获取指定年份的每个月的起始时间
?php/***@paramyear年份*/functiongetMonthByDate($year){//$year=2019;$yeararr=[];$month=[];for($i=1;$i=12;$i++){$yeararr[$i]=$year.-.$i;}foreach($yeararras$key=$value){$timestamp=strtotime($value);$start_time=date(Y-m-100:00:00,$timestamp);$mdays=date(t,$timestamp);$end_time=date(Y-m-.$mdays.23:59:59,$timestamp);$month[$key][start_time]=strtotime($start_time);$month[$key][end_time]=strtotime($end_time);}return$month;}? …
-
PHP获取当前时间戳和日期互相转换函数
?php//获取时间戳$date=time();//获取当前时间戳$date=mktime(0,0,0,10,10,2020);//获取指定时间的时间戳2020年10月10日0时0分0秒//日期转换为时间戳$date=2019-08-0808:08:08;$timestamp=strtotime($date);//将时间戳转换成日期$date=time();echodate(Y-m-d,$date);//输出格式化的日期(年-月-日)//将时间戳转换为时间格式$date=time();echodate(H:i:s,$date);//输出格式化的时间(小时:分钟:秒)//日期格式化$date=time();echodate(Y-m-dH:…
-
PHP怎么获取数组中的某个值
php可以获取数组某一项的值 方法1:使用“$数组名[下标]”语句获取“$数组名[下标]”可以访问数组中的指定下标的一个元素。 ?php$arr=array(香蕉,苹果,梨子,橙子,橘子,榴莲);var_dump($arr);echo数组下标为0的一个元素:.$arr[0].br;echo数组下标为2的一个元素:.$arr[2].br;echo数组下标为3的一个元素:.$arr[3].br;? 方法2:使用array_shift()函数获取 ?php$arr=array(香蕉,苹果,梨子,橙子,橘子,榴莲);var_dum…
-
PHP从数组中随机获取其中的一个数值
?php$img_num=array(6,8,10,15,16,17,19,20,21,24,25,30);//一组数组$fileath=$img_num[array_rand($img_num)];//随机获取该数组中一个值echo$fileath;? …
-
PHP获取指定月份的起止时间戳
?php/***获取指定月份的时间戳*@param$dateY-m*/functionget_month_begin_end($date){//$date=2018-11;$data[begin_time]=strtotime($date);//指定月份月初时间戳$data[end_time]=mktime(23,59,59,date(m,strtotime($date))+1,00);//指定月份月末时间戳return$data;}? …
-
PHP随机获取国内IP地址的方法
?php//随机IP地址//$randip=rand(1,254)...rand(1,254)...rand(1,254)...rand(1,254);//echo$randip;//随机国内IP地址$iprand=array(array(607649792,608174079),/*36.56.0.0-36.63.255.255*/array(1038614528,1039007743),/*61.232.0.0-61.237.255.255*/array(1783627776,1784676351),/*106.80.0.0-106.95.255.255*/array(2035023872,2035154943),/*121.76.0.0-121.77.255.255*/array(2078801920,2079064063),/*123.232.0.0-123.235.255.255*/array(-1950089216,-1948778497),/*139.196.0.0-139.215.255.255*/array(-142553907…
-
PHP获取指定日期之间的各个周
?php/***@paramsdate开始日期*@paramedate结束日期*/functionget_weeks($sdate,$edate){$range_arr=array();//检查日期有效性check_date(array($sdate,$edate));//计算各个周的起始时间do{$weekinfo=get_weekinfo_by_date($sdate);$end_day=$weekinfo[week_end_day];$start=substr_date($weekinfo[week_start_day]);$end=substr_date($weekinfo[week_end_day]);$range={$start}~{$end};$range_arr[]=$range;$sdate=date(Y-m-d,strtotime($sdate)+7*86400);}while($end_day$edate);return$range_arr;}/***检查日…
-
PHP通过时间戳获取某个日期段内的周几获取对应的日期 开始日期 结束日期
?php/***@paramdata日期array(start_date,end_data)*/functiongetDateByWeek($data){$start_date=strtotime($data[start_date]);$end_date=strtotime($data[end_date]);$days=($end_date-$start_date)/86400;$weekArr=array(周日,周一,周二,周三,周四,周五,周六);$newDate=array();//组建数组格式$dataWeek[日期]=星期for($i=0;$i$days;$i++){$num_week=date(w,$start_date+($i*86400));$dateWeek[date(Y-m-d,$start_date+($i*86400))]=$weekArr[$num_week];}//查找两个数组的交集,即获取提交的…