At 10:31 AM -0700 7/7/01, John Meyer wrote:
>When I go through a foreach loop, are the values of the individual 
>items in the array changed?
>For instance:
>$variables = array($author_firstname, $author_lastname, $author_dob, 
>$author_dod, $author_bio);
>  foreach($variables as $value) {
>         $value = strip_tags($value);
>         $value = AddSlashes($value);
>  }
>will the values be changed outside of the loop?

No, because $value is a copy the current array element, not simply a 
pointer to it. Furthermore, if I understand the documentation (see 
below) correctly, this construct (using the $variables array from 
above) -

        $i = 0;
        foreach ($variables as $value)
        $variables[$i] =AddSlashes( strip_tags($value));

- will not work either, since foreach() operates a COPY of the array. 
 From the docs at :

Note: When foreach first starts executing, the internal array pointer 
is automatically reset to the first element of the array. This means 
that you do not need to call reset() before a foreach loop.

Note: Also note that foreach operates on a copy of the specified 
array, not the array itself, therefore the array pointer is not 
modified as with the each() construct and changes to the array 
element returned are not reflected in the original array.

        - steve

>John Meyer
>If we didn't have Microsoft, we'd have to blame ourselves for all of 
>our programs crashing

+------ Factoid: Of the 100 largest economies in the world, 51 are ------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
|         |
+--- corporations ------ ---+

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to