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 Roberts on 05/26/06 08:35

"Chris" <Chris@dustbubble.nospam.com> wrote:
>
>I am clearly missing something simple here....
>...
>I am calling the function like this :
>
> $BrokenArray = array();
> $BrokenArray = $this->fileTree($this->ProjectRoot,".c");

Do you understand that the first statement is useless? This creates an
empty array, assigns it to $BrokenArray, and then promptly deletes it, to
be replaced by whatever fileTree returns.

> foreach (($this->fileTree($this->ProjectRoot,".c")) as $wibble)
> {
> print "Broken Array : $wibble <br>\n";
> }
>
>
>So it seems that the array in the function contains the right data, and by
>doing "$BrokenArray = array();" i suspect I am making sure the varible it is
>being assinged to isnt a scalar,

No. You can't change what fileTree returns. If it returns an array,
$BrokenArray will be an array. If it returns a scalar, $BrokenArray will
be a scalar. $this->fileTree has absolutely no clue that $BrokenArray
exists. If fileTree is supposed to return an array, then it must construct
an array and return it.

The other Tim gave you the rest of the hints you need to make this work.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

 

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

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