<title></title>
<body>
<div>
<?php
/**
* Gets the maximum and minimum of two coincident periods
* [Get_min_max description]
* @author Jimswoo 20161016 <[<email address>]>
* @param [Type] $a [description]
* @param [Type] $b [description]
* @return [Type] [description]
*/
function Get_min_max ($a, $b) {
$sort = Array_merge ($a, $b);
Array_multisort ($sort);
$end = Array_pop ($sort);
return $sort [0]. ' # '. $end;//array ($sort [0], $end);
}
/**
* [Is_repeat description]
* Whether the two-period coincidence
* @author Jimswoo 20161016 <[<email address>]>
* @param [Type] $target [description]
* @param [Type] $compare [description]
* @param boolean $run [description]
* @return Boolean [description]
*/
function Is_repeat ($target, $compare, $run = True) {
$min = $compare [0];
$max = $compare [1];
$res = false;
foreach ($target as $v) {
if (($v >= $min && $v <= $max)) {
$res = true;
Break
}
}
if ($run &&! $res) {
$res = Is_repeat ($compare, $target, false);
}
return $res;
}
/**
* Convert the value of a period from a string to an array
* @author Jimswoo 20161016 <[<email address>]>
* [ChangeValue description]
* @param [Type] $val [description]
* @return [Type] [description]
*/
function ChangeValue ($val) {
$val = Array_unique ($val);
$list = Array ();
foreach ($val as $v) {
$list [] = Explode (' # ', $v);
}
return $list;
}
/**
* [Main_run description]
* Comparison method
* @author Jimswoo 20161016 <[<email address>]>
* @param [Type] $all [description]
* @return [Type] [description]
*/
function Main_run ($all) {
$leng = count ($all);
$result = $un = Array ();
$count = 0;
for ($i = 0; $i < $leng; $i + +) {
for ($j = $leng-1; $j >= $i; $j-) {
if (Is_repeat ($all [$j], $all [$i])) {
if ($j! = $i) {
$count + +;
}else{
$un [] = $all [$i][0]. ' # '. $all [$i][1];
}
$result [] = Get_min_max ($all [$j], $all [$i]);
$all [$i] = $all [$j] = array ( -3,-2);
}else{
$un [] = $all [$i][0]. ' # '. $all [$i][1];
}
}
}
$result = Array_merge ($result, $un);
if ($count = = 0) {
$result = $all;
}
Return Array (' c ' = = $count, ' V ' = $result);
}
/**
* [Getcomfirmtimes description]
* @author Jimswoo 20161016 <[<email address>]>
* @param [Type] $all [description] format array (array (2,4), Array (34,332))
* @return [Type] [description]
*/
function Getcomfirmtimes ($all) {
if (empty ($all)) {
return Array ();
}
$c = 0;
do{
$is _end = Main_run ($all);
if ($is _end[' C ']! = 0) {
Var_dump ($all);
$all = ChangeValue ($is _end[' V ');
}else{
foreach ($all as $k = = $v) {
if ($v [0] = =-3) {
Unset ($all [$k]);
}
}
}
$c + +;
}while ($is _end[' C ']! = 0 && $c < 120);
return $all;
}
$test = Array (
Array (2,6),
Array (5,9),
Array (10,11),
Array (15,20),
Array (22,23),
Array (13,19)
);
$res = Getcomfirmtimes ($test);
Print_r ($res);
?>
</div>
</body>
This article is from the "12005322" blog, please be sure to keep this source http://12015322.blog.51cto.com/12005322/1876592
A method of coincidence and integration of PHP's time period