Re: Differences

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

 



On Wed, Oct 3, 2012 at 10:03 PM, tamouse mailing lists
<tamouse.lists@xxxxxxxxx> wrote:
> On Wed, Oct 3, 2012 at 9:57 PM, David McGlone <david@xxxxxxxxxxxxx> wrote:
>> Absolutely. I also think I learned that return can also work like echo if the
>> code is written correctly.
>
>
> No, no, no. Return does NOT do the same thing as echo, nor vice versa.
> If you do try to make things work this way you are doing things
> incorrectly. If you do try to make things work this way and it
> actually works, you have gotten lucky, but are still doing it
> incorrectly.

Let's try another example, based on your code:

Example 1: using return
=======================

function completeImageFilename($prefix) //correcting function name
{
  $matches = glob('images/property_pics/'.$prefix.'*');
  foreach($matches as $filename){
  return $filename;
  }
}

echo "This is the complete image file name:
".completeImageFilename($row['MLS_No']) . PHP_EOL;

You will get one line of output with the text from the echo statement
and the first filename that matches.

Example 2: using echo
=====================

function completeImageFilename($prefix) //correcting function name
{
  $matches = glob('images/property_pics/'.$prefix.'*');
  foreach($matches as $filename){
    echo "This is the file name from inside completeImageFilename: " .
$filename . PHP_EOL;
  }
}

echo "This is the complete image file name:
".completeImageFilename($row['MLS_No']) . PHP_EOL;

You will get several lines of output for each filename that matches
with the text from the echo statement inside the function, then one
more line that will contain *just* the text from the final echo
statement:

This is the file name from inside completeImageFilename:
images/property_pics/151136.jpg
This is the file name from inside completeImageFilename:
images/property_pics/151137.jpg
This is the file name from inside completeImageFilename:
images/property_pics/151138.jpg
This is the file name from inside completeImageFilename:
images/property_pics/151139.jpg
This is the complete image file name:

(the file names are bogus and just made up by me to illustrate)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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