You are here: Re: returning an array from a function « PHP Programming Language « IT news, forums, messages
Re: returning an array from a function

Posted by tim on 11/02/62 11:48

Chris wrote:

Hi

>
> I have a function (fileTree) that recursively reads all the files in a
> directory passed to it, and returns an array of the files, I have included
> the code for this function below.

> if (is_dir($directory. "/" . $file))
> {
> $dir_array = array_merge($dir_array, $this->fileTree($directory.
> "/" . $file,$ext));
> $file = $directory . "/" . $file;
> $dir_array[] = preg_replace("/\/\//si", "/", $file);
> }

In the above code, the files found in the subdirectories aren't being
added to $file_array.

>
> When I call this function, the bit of debug code at the end will correctly
> print the array of files I am expecting, and then returns.

Try print "In new dir<br>" and just before the foreach loop to see what
I mean, its finding each file but its not passing what it found to the
calling function.

> foreach ($file_array as $wibble)
> {
> print "Wibble : $wibble <br>\n";
> }
>
> return ($file_array);
> }

Hope that helps,

Tim

 

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

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