Re: Differences

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday, October 03, 2012 10:01:50 PM James wrote:
> All of the images are displaying because you're simply instructing the
> function to print out each file found with your call to glob(). The glob()
> function returns an indexed array containing files found in the path you
> specified, or an empty array if no files were found or false if glob()
> failed. When I say "print" I'm referring to you using the echo language
> construct, however, print is also another language construct.
> 
> Therefore using echo in your function allows the foreach loop to continue
> iterating through the array of files returned by glob(). Replacing that
> echo with the return, the function ones one iteration in the foreach loop
> and stops, returning that value. In your case, the function is returning
> index 0 of the array returned by glob().
> 
> Make more sense?

Absolutely. I also think I learned that return can also work like echo if the 
code is written correctly.


> 
> David McGlone <david@xxxxxxxxxxxxx> wrote:
> >On Wednesday, October 03, 2012 08:55:29 PM admin wrote:
> >> > Hi everyone, I have been playing around with some code the list
> >
> >helped me
> >
> >> with a while back and I'm not grasping the concept between return and
> >
> >echo
> >
> >> and the PHP manual doesn't answer this, unless I'm missing something.
> >
> >There
> >
> >> is an > example at the very bottom of PHP's return manual, but it's
> >> confusing.
> >> 
> >> > So now I'm left wondering why return will only give me the first
> >
> >result in
> >
> >> an array, but echo will give me all the results of the array. Using
> >
> >stuart's
> >
> >> example he had sent me a while back I've messed around with it and
> >
> >modified
> >
> >> it > to better understand it:
> >> > function filename($prefix)
> >> >
> >> >{
> >> >
> >> >  $matches = glob('images/property_pics/'.$prefix.'*');
> >> >  foreach($matches as $filename){
> >> >  return $filename;
> >> >  
> >> >         }
> >> >
> >> >}
> >> >
> >> >echo completeImageFilename($row['MLS_No']);
> >> >
> >> >With the above code I only get the first image of each picture name,
> >
> >but
> >
> >> when I change return to echo, it groups and displays all the pics
> >
> >that have
> >
> >> the same picture name.
> >> 
> >> >--
> >> >David M.
> >> 
> >> The first loop and return is all you will get.
> >> Put the information into an array and return the array once the array
> >
> >is
> >
> >> built.
> >
> >I think I understand what your saying, but what I don't understand is
> >that
> >when I leave the current code intact and replace return $filename with
> >echo
> >$filename in the function, all the images display. Is this intended
> >behavior
> >between return and echo or is it just bad code on my part?
> >
> >David M.
-- 
David M.


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux