function gmgetdate($ts = null){ //echo $ts; $k = array('seconds','minutes','hours','mday','wday','mon','year','yday','weekday','month',0); return(array_comb($k,split(":",gmdate('m/d/y H:i:s',is_null($ts)?time():$ts)))); //return date_format($ts, "m/d/y H:i:s"); //return date('m/d/Y H:i:s', $ts); }
function gmgetdate($ts = null) { $k = array('seconds', 'minutes', 'hours', 'mday', 'wday', 'mon', 'year', 'yday', 'weekday', 'month', 0); //split has been deprecated...I think that explode will work here //return(array_comb($k,split(":",gmdate('s:i:G:j:w:n:Y:z:l:F:U',is_null($ts)?time():$ts)))); return array_comb($k, explode(":", gmdate('s:i:G:j:w:n:Y:z:l:F:U', is_null($ts) ? time() : $ts))); }
function gmgetdate($ts = null) { $k = array('seconds', 'minutes', 'hours', 'mday', 'wday', 'mon', 'year', 'yday', 'weekday', 'month', 0); return array_comb($k, split(":", gmdate('s:i:G:j:w:n:Y:z:l:F:U', is_null($ts) ? time() : $ts))); }
/** * Format the field for database insertion. * * @param string $field The data from the field to be formated. * @return string Returns the formated field. */ function ConsistFormat(&$field) { $f = preg_split('/[\\s,.\\/\\-:]/', strtolower($this->format), -1, PREG_SPLIT_NO_EMPTY); $v = preg_split('/[\\s,.\\/\\-:]/', $field, -1, PREG_SPLIT_NO_EMPTY); if (count($f) != count($v)) { return "''"; } $dt = array_comb($f, $v); switch ($this->type) { case FT_DATE: return "'" . date('Y-m-d', mktime(0, 0, 0, $dt['m'], $dt['d'], $dt['y'])) . "'"; break; case FT_TIME: return "'" . date('H:i:s', mktime($dt['h'], $dt['i'], $dt['s'])) . "'"; break; case FT_DATETIME: return "'" . date('Y-m-d H:i:s', mktime($dt['h'], $dt['i'], $dt['s'], $dt['m'], $dt['d'], $dt['y'])) . "'"; break; } return "''"; }
Да се напише метод, който сумира 2 масива в трети масив ($c[$i] = $a[$i] + $b[$i]). Двата масива може да са с различен размер. */ function array_comb($a, $b) { $c = array(); $a_count = count($a); $b_count = count($b); if ($a_count > $b_count) { for ($i = 0; $i < $a_count; $i++) { if ($b[$i] == '') { $b[$i] = 0; } $c[$i] = $a[$i] + $b[$i]; } } else { for ($i = 0; $i < $b_count; $i++) { if ($a[$i] == '') { $a[$i] = 0; } $c[$i] = $b[$i] + $a[$i]; } } foreach ($c as $key => $value) { echo '[' . $key . '-' . $value . ']'; } } $arr1 = array(5, 8, 16); $arr2 = array(4, 3, 1, 15, 5); array_comb($arr1, $arr2);