You are here: Re: problem returning value using recursive function « All PHP « IT news, forums, messages
Re: problem returning value using recursive function

Posted by Steve on 04/12/07 14:25

"Vince Morgan" <vinhar@REMOVEoptusnet.com.au> wrote in message
news:461e36c1$0$5743$afc38c87@news.optusnet.com.au...
| "Steve" <no.one@example.com> wrote in message
| news:juqTh.10$G46.6@newsfe04.lga...
|
| > that's not quite true either...he needlessly enters the next recursion
and
| > if $d, immediately returns w/o incrementing $l.
| >
| > :)
| >
| >
|
| Are you sure Steve?

yes.

| function level($n,$l=0,$d=false) {
| if ($d) { return $l; }
| else {
| $ff=get_folders();
| for ($i=0;$i<count($ff);$i++) {
| if ($n==$ff[$i][0]) {
| if ($ff[$i][4]!=0) {
|
| Here he increments again before calling level()

true enough, however when he actually expects a return value rather than
recurse level() again, there is no need to call level(), and further, no
need for $d at all. the return should be immediate. notice again, however,
that level() never sets anything for return to return into?

| $l++;
| level($ff[$i][4],$l,$d);
| }
| else {
|
| But here he has found what he wants and it should return on the next
| recursion.

needlessly, true...but into what does he return $l from any iteration?

| $d=true;
| level($ff[$i][0],$l,$d);
| }
| }
| }
| }
| }
|
| I could be wrong, it wouldn't be the first time ;)

me too. i've lost count.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация