Tema: Re: rekursija
Autorius: 323
Data: 2010-03-01 15:08:30
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.5921" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>jei prasuka 6000, turi ir 12000 prasukt. Gal suki 
per web'a ir suveikia script time-outas... bandyk per command prompta 
sukt.</FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV>"bk" &lt;<A href="mailto:a@a.com">a@a.com</A>&gt; wrote in message <A 
  href="news:hm8urh$to4$1@trimpas.omnitel.net">news:hm8urh$to4$1@trimpas.omnitel.net</A>...</DIV><FONT 
  face=Arial><FONT size=2>
  <DIV>sveiki, </DIV>
  <DIV>&nbsp;</DIV>
  <DIV>padariau savo pirmaja rekursija, kuri formuoja multidimensional 
  masyva.veikti tai lyg viskas veikia, ale pvz 6000 irasu suka ~20 sekundziu, o 
  12000 - isvis nesulaukiau... </DIV>
  <DIV>taigi, kas negerai su sia funckija? slieku savo jegomis daugiau nerandu, 
  bo neesu itin geras egzpertas :)</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&lt;? </DIV>
  <DIV>function get_child($data, $pid = null) {<BR>&nbsp;&nbsp;$tree = 
  array();<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;foreach( $data as $key =&gt; $d ) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( $d['parent_id'] == 
  $pid ) {<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;$tree[$d['id']] = 
  array<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'parent_id' 
  =&gt; $d['parent_id']<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  &nbsp;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  unset($data[$key]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;$children =&nbsp; $this-&gt;get_child($data, 
  $d['id']);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;if($children) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$tree[$d['id']]['children'] = 
  $children;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;return 
  $tree;<BR>&nbsp;}&nbsp;</DIV>
  <DIV>?&gt;</DIV></BLOCKQUOTE></FONT></FONT></BODY></HTML>