'32' => array
        (
            'FROM' => 250,
            'TO' => 174,
            'DAYS' => 21
        ),
'33' => array
        (
            'FROM' => 188,
            'TO' => 174,
            'DAYS' => 22
        ),
'34' => array
        (
            'FROM' => 186,
            'TO' => 174,
            'DAYS' => 23
        ),
'35' => array
        (
            'FROM' => 184,
            'TO' => 174,
            'DAYS' => 24
        ),
'36' => array
        (
            'FROM' => 181,
            'TO' => 174,
            'DAYS' => 25
        ),
'37' => array
        (
            'FROM' => 176,
            'TO' => 174,
            'DAYS' => 26
        ),
'38' => array
        (
            'FROM' => 177,
            'TO' => 174,
            'DAYS' => 27
        ),
'39' => array
        (
            'FROM' => 178,
            'TO' => 174,
            'DAYS' => 28
        ),
'40' => array
        (
            'FROM' => 171,
            'TO' => 175,
            'DAYS' => 29
        ),
'41' => array
        (
            'FROM' => 171,
            'TO' => 176,
            'DAYS' => 30
        ),
'42' => array
        (
            'FROM' => 171,
            'TO' => 177,
            'DAYS' => 31
        ),
'43' => array
        (
            'FROM' => 171,
            'TO' => 178,
            'DAYS' => 32
        ),
'44' => array
        (
            'FROM' => 191,
            'TO' => 180,
            'DAYS' => 33
        ),
'45' => array
        (
            'FROM' => 171,
            'TO' => 181,
            'DAYS' => 34
        ),
'46' => array
        (
            'FROM' => 171,
            'TO' => 182,
            'DAYS' => 35
        ),
'47' => array
        (
            'FROM' => 142,
            'TO' => 183,
            'DAYS' => 36
        ),
'48' => array
        (
            'FROM' => 171,
            'TO' => 184,
            'DAYS' => 37
        ),
'49' => array
        (
            'FROM' => 171,
            'TO' => 185,
            'DAYS' => 38
        ),
'50' => array
        (
            'FROM' => 171,
            'TO' => 186,
            'DAYS' => 39
        ),
'51' => array
        (
            'FROM' => 171,
            'TO' => 187,
            'DAYS' => 40
        ),
'52' => array
        (
            'FROM' => 171,
            'TO' => 188,
            'DAYS' => 41
        ),
'53' => array
        (
            'FROM' => 201,
            'TO' => 197,
            'DAYS' => 42
        ),
'54' => array
        (
            'FROM' => 252,
            'TO' => 199,
            'DAYS' => 43
        ),
'55' => array
        (
            'FROM' => 252,
            'TO' => 201,
            'DAYS' => 44
        ),
'56' => array
        (
            'FROM' => 197,
            'TO' => 213,
            'DAYS' => 45
        ),
'57' => array
        (
            'FROM' => 213,
            'TO' => 214,
            'DAYS' => 46
        ),
'58' => array
        (
            'FROM' => 4,
            'TO' => 249,
            'DAYS' => 47
        ),
'59' => array
        (
            'FROM' => 171,
            'TO' => 250,
            'DAYS' => 48
        ),
'60' => array
        (
            'FROM' => 183,
            'TO' => 251,
            'DAYS' => 49
        ),
'61' => array
        (
            'FROM' => 141,
            'TO' => 252,
            'DAYS' => 50
        ),
'62' => array
        (
            'FROM' => 251,
            'TO' => 253,
            'DAYS' => 51
        ),
'63' => array
        (
            'FROM' => 253,
            'TO' => 254,
            'DAYS' => 52
        ),
'64' => array
        (
            'FROM' => 162,
            'TO' => 400,
            'DAYS' => 53
        ),
'65' => array
        (
            'FROM' => 199,
            'TO' => 401,
            'DAYS' => 54
        ),
'66' => array
        (
            'FROM' => 400,
            'TO' => 402,
            'DAYS' => 55
        ),
'67' => array
        (
            'FROM' => 401,
            'TO' => 402,
            'DAYS' => 56
        ),
'68' => array
        (
            'FROM' => 168,
            'TO' => 403,
            'DAYS' => 57
        ),
'69' => array
        (
            'FROM' => 403,
            'TO' => 404,
            'DAYS' => 58
        ),
'70' => array
        (
            'FROM' => 404,
            'TO' => 405,
            'DAYS' => 59
        ),
'71' => array
        (
            'FROM' => 405,
            'TO' => 406,
            'DAYS' => 60
        ),
'72' => array
        (
            'FROM' => 406,
            'TO' => 407,
            'DAYS' => 61
        ),
'73' => array
        (
            'FROM' => 407,
            'TO' => 408,
            'DAYS' => 62
        ),
'74' => array
        (
            'FROM' => 408,
            'TO' => 409,
            'DAYS' => 63
        ),
'75' => array
        (
            'FROM' => 171,
            'TO' => 410,
            'DAYS' => 64
        ),
'76' => array
        (
            'FROM' => 171,
            'TO' => 411,
            'DAYS' => 65
        ),
'77' => array
        (
            'FROM' => 171,
            'TO' => 412,
            'DAYS' => 66
        )
);
其中FROM,TO,DAYS分别表示任务的走向(FROM完成了才能开始TO任务)及工期,开始任务为781,801,假设开始日期为2007-06-12,如何根据工期递归求出各任务的起始日期?我写了一个递归,可是只有在一条线上的任务才正确,如果多条分支合一就错了。

解决方案 »

  1.   

    FROM TO 这样的结构就注定了是一条线 怎么可能多条呢 除非FROM TO TO TO... 
    数据结构错误 鉴定完毕!这个TO完全可以省略 没什么用处 任务应该有个编号 而不是自动的序号array(
     171=>array('FROM'=>0,  'DAYS'=>100),
     172=>array('FROM'=>171,'DAYS'=>10),
     173=>array('FROM'=>172,'DAYS'=>99),
     174=>array('FROM'=>172,'DAYS'=>5),
     ......
    );
      

  2.   

    function find(&$ar, $a) {
      $r = array();
      foreach($ar as $i=>$v) {
        if($v['FROM'] == $a ) $r[] = $i;
      }
      return $r;
    }function foo($a, $n=0) {
      global $arr,$date;
      $r = array();
      $t = find($arr, $a);
      foreach($t as $i) {
        if(!isset($arr[$i]['START'])) {
          $arr[$i]['START'] = date('Y-m-d', strtotime("+$n day $date"));
        }else {
          $arr[$i]['START'] .= ','.date('Y-m-d', strtotime("+$n day $date"));
        }
        $r['CHILD'][] =foo($arr[$i]['TO'], $n+$arr[$i]['DAYS']);
      }
      return $r;
    }$date = '2007-06-12';
    foo(781);
    foo(801);print_r($arr);
      

  3.   

    重新描述:A表
    id  days
    553 3
    562 6
    563 3
    554 15
    555 12
    556 6
    557 9
    558 4
    559 11
    560 20
    561 19B表
    fromid  toid
    561 562
    553 554
    554 555
    555 556
    556 557
    556 558
    557 559
    559 560
    558 561
    560 561
    562 563开始节点:553.开始日期:2008-07-03A表的days表示该ID对应的任务完成需要的天数,
    B表的fromid,toid均来自于A表的id
    fromid,toid分别表示fromid任务完成了,toid任务才能开始.
    开始的节点为553,当然,也会存在多个任务同时开始的情况
    求出来的结果应该如下:
    id begindates enddates
    553 2008-7-3 2008-7-5
    562 2008-10-6 2008-10-11
    563 2008-10-12 2008-10-14
    554 2008-7-6 2008-7-20
    555 2008-7-21 2008-8-1
    556 2008-8-2 2008-8-7
    557 2008-8-8 2008-8-16
    558 2008-8-8 2008-8-11
    559 2008-8-17 2008-8-27
    560 2008-8-28 2008-9-16
    561 2008-9-17 2008-10-5
      

  4.   

    我写的fun
    $updatelist = array();
    //当前任务为其它任务的前置任务,递归更新其它任务的开始时间
    function modDate($db, $current_job, $pid, $job_id, &$updatelist){
    $sql = "select t.JOB_FLAG, t.FROMID, t.JOBID, p.JOB_DAY from B t,A p where t.PID = :pid and t.FROMID = :job_id and p.JOBID = t.JOBID and p.PID = t.PID and p.PID = :pid";
    $st = $db->Execute($sql, array('pid'=>$pid, 'job_id'=>$job_id));
    while($row = $st->FetchRow()){
    if($row['JOBID'] == $current_job) continue;
    if($row['JOB_FLAG'] == '1') continue;
    if(!in_array($row['JOBID'], $updatelist)) $updatelist[] = $row['JOBID'];
    $drow = $db->GetRow("select max(END_DATE) END_DATE from A t,B p where t.PID = p.PID and t.JOBID = p.FROMID and p.PID = :pid and p.JOBID = :job_id", array('pid'=>$pid,'job_id'=>$row['JOBID']));
    //最早开始时间为其所有的前置任务的最迟结束时间
    $minus_day = $row['JOB_DAY'] - 1;

    $max_end_date = $drow['END_DATE'];
    $date_list = explode("-",$max_end_date);
    $max_end_date = date('Y-m-d', mktime(0, 0, 0, $date_list[1], $date_list[2]+1, $date_list[0])); $nextday = date('Y-m-d', mktime(0, 0, 0, 
    substr($max_end_date,5,2), substr($max_end_date,8,2) + $minus_day, substr($max_end_date,0,4)));
    $db->Execute("update A SET BEGIN_DATE = :begin_date,END_DATE = :end_date where PID = :pid and JOBID = :job_id",array('begin_date'=>$max_end_date,'end_date'=>$nextday,'pid'=>$pid, 'job_id'=>$row['JOBID']));
    $db->Execute("update B set JOB_FLAG = '1' where PID = :pid and JOBID = :job_id and FROMID = :fromid",array('pid'=>$pid, 'job_id'=>$row['JOBID'],'fromid'=>$row['FROMID']));
    }
    if(count($updatelist)>0){
    $job_id = array_pop($updatelist);
    modDate($db, $current_job, $pid, $job_id, $updatelist);
    }
    }
      

  5.   

    任务之间的关系图如下:
    <html xmlns:v="urn:schemas-microsoft-com:vml">
    <HEAD>
    <TITLE>网络图</TITLE>
    </HEAD>
    <STYLE>
     v\:* { BEHAVIOR: url(#default#VML) }
    </STYLE>
    </HEAD>
    <BODY>
    <v:group ID="group1" style="position:relative;WIDTH:1200px;HEIGHT:1200px;" coordsize = "1800,1800">
    <v:Rect style="position:absolute;width:120px;height:54px;left:0px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A1[553,3]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:1120px;top:160px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A12[562,6]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:800px;top:240px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A13[563,3]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:160px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A2[554,15]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:320px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A3[555,12]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:480px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A4[556,6]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:640px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A5[557,9]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:640px;top:80px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A6[558,4]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:800px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A7[559,11]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:960px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A9[560,20]</v:TextBox>
    </v:Rect>
    <v:Rect style="position:absolute;width:120px;height:54px;left:1120px;top:0px;" fillcolor='#E8EFF7'>
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/>
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A11[561,19]</v:TextBox>
    </v:Rect>
    <v:line from="120,27" to="160,27" style="position:absolute;"/><v:line from="152,22" to="160,27" style="position:absolute;"/>
    <v:line from="152,32" to="160,27" style="position:absolute;"/>
    <v:line from="280,27" to="320,27" style="position:absolute;"/><v:line from="312,22" to="320,27" style="position:absolute;"/>
    <v:line from="312,32" to="320,27" style="position:absolute;"/>
    <v:line from="440,27" to="480,27" style="position:absolute;"/><v:line from="472,22" to="480,27" style="position:absolute;"/>
    <v:line from="472,32" to="480,27" style="position:absolute;"/>
    <v:line from="600,27" to="640,27" style="position:absolute;"/><v:line from="632,22" to="640,27" style="position:absolute;"/>
    <v:line from="632,32" to="640,27" style="position:absolute;"/>
    <v:line from="545,54" to="545,107" style="position:absolute;"/><v:line from="545,107" to="640,107" style="position:absolute;"/><v:line from="632,102" to="640,107" style="position:absolute;"/>
    <v:line from="632,112" to="640,107" style="position:absolute;"/>
    <v:line from="760,27" to="800,27" style="position:absolute;"/><v:line from="792,22" to="800,27" style="position:absolute;"/>
    <v:line from="792,32" to="800,27" style="position:absolute;"/>
    <v:line from="760,102" to="1175,102" style="position:absolute;"/><v:line from="1175,102" to="1175,54" style="position:absolute;"/><v:line from="1179,62" to="1175,54" style="position:absolute;"/>
    <v:line from="1169,62" to="1175,54" style="position:absolute;"/>
    <v:line from="920,27" to="960,27" style="position:absolute;"/><v:line from="952,22" to="960,27" style="position:absolute;"/>
    <v:line from="952,32" to="960,27" style="position:absolute;"/>
    <v:line from="1080,27" to="1120,27" style="position:absolute;"/><v:line from="1112,22" to="1120,27" style="position:absolute;"/>
    <v:line from="1112,32" to="1120,27" style="position:absolute;"/>
    <v:line from="1180,54" to="1180,160" style="position:absolute;"/><v:line from="1184,152" to="1180,160" style="position:absolute;"/>
    <v:line from="1174,152" to="1180,160" style="position:absolute;"/>
    <v:line from="1175,214" to="1175,267" style="position:absolute;"/><v:line from="1175,267" to="920,267" style="position:absolute;"/><v:line from="928,272" to="920,267" style="position:absolute;"/>
    <v:line from="928,262" to="920,267" style="position:absolute;"/>
    </v:group>
    </BODY>
    </HTML>
      

  6.   

    我想问一下,你FROM TO怎么会有多条??难道是from a to {b,c,d}?这样?
      

  7.   

    from to 是单向,但是会有多个from到同一个to,看下我上面贴的图就知道了
      

  8.   

    <html xmlns:v="urn:schemas-microsoft-com:vml"> 
    <HEAD> 
    <TITLE>网络图 </TITLE> 
    </HEAD> 
    <STYLE> 
    v\:* { BEHAVIOR: url(#default#VML) } 
    </STYLE> 
    </HEAD> 
    <BODY> 
    <v:group ID="group1" style="position:relative;WIDTH:1200px;HEIGHT:1200px;" coordsize = "1800,1800"> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:0px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A1[553,3] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:1120px;top:160px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A12[562,6] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:800px;top:240px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A13[563,3] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:160px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A2[554,15] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:320px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A3[555,12] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:480px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A4[556,6] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:640px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A5[557,9] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:640px;top:80px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A6[558,4] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:800px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A7[559,11] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:960px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A9[560,20] </v:TextBox> 
    </v:Rect> 
    <v:Rect style="position:absolute;width:120px;height:54px;left:1120px;top:0px;" fillcolor='#E8EFF7'> 
    <v:shadow on="T" type="single" color="#b3b3b3" offset="5px,5px"/> 
    <v:TextBox inset="2pt,2pt,2pt,2pt" style="font-size:10.2pt;">A11[561,19] </v:TextBox> 
    </v:Rect> 
    <v:line from="120,27" to="160,27" style="position:absolute;"/> <v:line from="152,22" to="160,27" style="position:absolute;"/> 
    <v:line from="152,32" to="160,27" style="position:absolute;"/> 
    <v:line from="280,27" to="320,27" style="position:absolute;"/> <v:line from="312,22" to="320,27" style="position:absolute;"/> 
    <v:line from="312,32" to="320,27" style="position:absolute;"/> 
    <v:line from="440,27" to="480,27" style="position:absolute;"/> <v:line from="472,22" to="480,27" style="position:absolute;"/> 
    <v:line from="472,32" to="480,27" style="position:absolute;"/> 
    <v:line from="600,27" to="640,27" style="position:absolute;"/> <v:line from="632,22" to="640,27" style="position:absolute;"/> 
    <v:line from="632,32" to="640,27" style="position:absolute;"/> 
    <v:line from="545,54" to="545,107" style="position:absolute;"/> <v:line from="545,107" to="640,107" style="position:absolute;"/> <v:line from="632,102" to="640,107" style="position:absolute;"/> 
    <v:line from="632,112" to="640,107" style="position:absolute;"/> 
    <v:line from="760,27" to="800,27" style="position:absolute;"/> <v:line from="792,22" to="800,27" style="position:absolute;"/> 
    <v:line from="792,32" to="800,27" style="position:absolute;"/> 
    <v:line from="760,102" to="1175,102" style="position:absolute;"/> <v:line from="1175,102" to="1175,54" style="position:absolute;"/> <v:line from="1179,62" to="1175,54" style="position:absolute;"/> 
    <v:line from="1169,62" to="1175,54" style="position:absolute;"/> 
    <v:line from="920,27" to="960,27" style="position:absolute;"/> <v:line from="952,22" to="960,27" style="position:absolute;"/> 
    <v:line from="952,32" to="960,27" style="position:absolute;"/> 
    <v:line from="1080,27" to="1120,27" style="position:absolute;"/> <v:line from="1112,22" to="1120,27" style="position:absolute;"/> 
    <v:line from="1112,32" to="1120,27" style="position:absolute;"/> 
    <v:line from="1180,54" to="1180,160" style="position:absolute;"/> <v:line from="1184,152" to="1180,160" style="position:absolute;"/> 
    <v:line from="1174,152" to="1180,160" style="position:absolute;"/> 
    <v:line from="1175,214" to="1175,267" style="position:absolute;"/> <v:line from="1175,267" to="920,267" style="position:absolute;"/> <v:line from="928,272" to="920,267" style="position:absolute;"/> 
    <v:line from="928,262" to="920,267" style="position:absolute;"/> 
    </v:group> 
    </BODY> 
    </HTML>
      

  9.   

    存在这样的情况,就像从不同的起点出发,到达终点有不同的路径类似。。
    kel帐户被说成恶意刷屏,csdn绝对有问题了
      

  10.   

    lz应该把问题尽量简单化,搞这么多数据干嘛....try:
    //对结果集做一些简单处理.
    $a[561] = array('to'=>562,'day'=>19); 
    $a[553] = array('to'=>554,'day'=>3) ;
    $a[554] = array('to'=>555,'day'=>15);
    $a[555] = array('to'=>556,'day'=>12); 
    $a[556][0] = array('to'=>557,'day'=>6); 
    $a[556][1] = array('to'=>558,'day'=>6); 
    $a[557] = array('to'=>559,'day'=>9); 
    $a[559] = array('to'=>560,'day'=>11); 
    $a[558] = array('to'=>561,'day'=>4); 
    $a[560] = array('to'=>561,'day'=>20); 
    $a[562] = array('to'=>563,'day'=>6);
    $a[563] = array('to'=>'','day'=>3);//获取日期
    function getAllTaskDays($startNo,$array,$startDay)
    {
    static $store = array();

    if($array[$startNo])
    {
    if($array[$startNo][0])
    {
    foreach($array[$startNo] as $v)
    {
    $day = $v['day'] - 1;
    $toId = $v['to'];
    if($array[$toId]) getAllTaskDays($toId,$array,date('Y-m-d',strtotime($startDay." +{$v['day']} days"))); 
    //echo $startNo."--"."begin_date:".$startDay." end_date:".date('Y-m-d',strtotime($startDay." +{$day} days"))."<br/>"; }

    }
    else
    {
    $day = $array[$startNo]['day'] - 1;
    $toId = $array[$startNo]['to'];
    //echo $startNo."--"."begin_date:".$startDay." end_date:".date('Y-m-d',strtotime($startDay." +{$day} days"))."<br/>";
    if($array[$toId]) getAllTaskDays($toId,$array,date('Y-m-d',strtotime($startDay." +{$array[$startNo]['day']} days")));
    }
    if(!$store[$startNo] || $store[$startNo]['start_date'] < $startDay)
    {
    $store[$startNo]['start_date'] = $startDay;
    $store[$startNo]['end_date']   = date('Y-m-d',strtotime($startDay." +{$day} days"));
    }
    }
    return $store;
    }
    //例子
    echo "<pre>";
    $startTaskNo =  553;
    print_r(getAllTaskDays($startTaskNo,$a,"2008-07-03"));
    exit;
      

  11.   

    foolbirdflyfirst:
    用了上面的递归,结果不对
      

  12.   

    foolbirdflyfirst:
    是我自己把数据弄错了.