Hi, that's something I tripped over myself when I started out :)
foreach takes one element after another from the array and copies it into that new variable - in your case $value ... you can modify it all you want - the value 'still' being in the array will not be affected. you could operate directly one the value in the array with: // calculate the number of items in the array before starting the // loop - will be faster the larger the array $arCount = count($array); for ($i = 0; $i < $arCount; ++$i) { stripslashes($array[$i]); } although, on second thought I don't think that stripslashes will do what you want it to, because it's designed to get rid of slashes before special characters like the songle quote (I think, but try it for yourself). So, if you want your array to change from $array = ('zero\0', 'one\1', 'two\2', 'three\3'); to $array = ('zero0', 'one1', 'two2', 'three3'); (as I understood) then I'd recommend using str_replace. That one also has the advantage of taking arrays as arguments so you can save the whole for / foreach $array = str_replace('\'', '', $array); Richard Friday, April 30, 2004, 6:01:30 AM, thus was written: > I'm practicing from a beginning PHP book regarding > arrays and the PHP manual, so please no one flame me > that I didn't try to research before posting. I'm > thinking that what I want to do requires me to use the > function array_walk or a foreach loop, but I'm not so > sure so maybe someone help here can help. > I want to have an array, perform an action on the > values in the array, and have those actions > permanently affect the values in the array. Here's > something I've written to test it out how I thought it > could be done: > <?php > $array = ('zero\0', 'one\1', 'two\2', 'three\3'); > // look at array before changes > print_r($array); > // maybe use foreach or array_walk next? > foreach ($array as $value) > { > stripslashes($value); > } > // look at array after changes > print_r($array); ?>> > I'm guessing by now someone can see my error, but I > don't know enough programming to spot it. What I > thought would happen is my values would have the > backslash removed in the second print_r(). What I > would want is for any changes made in the array > (meaning my "values") to be permanent in the array > afterwards. If I can accomplish the code above, I > figure I can create my own functions to affect changes > on values or at least better understand what I'm > looking at in other people's examples/comments at the > online PHP manual. > Thank you in advance. > Katie > __________________________________ > Do you Yahoo!? > Win a $20,000 Career Makeover at Yahoo! HotJobs > http://hotjobs.sweepstakes.yahoo.com/careermakeover -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php