• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PHP - Changing element in the loop

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But when I don't use unset() function and print_r($color), it outputs YELLOW as result, I don't get why it outputs only YELLOW?

Thanks in Advance ;)
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the completion of the foreach loop $color contains the last array element changed to upper case ie it contains "YELLOW". If you print out it's contents using print_r it will output "YELLOW" unless you have already unset it.

What was it you were trying to do? did you want to change each element of the array to upper case, if so you need to use the following foreach loop (note the addition of '&'):

reply
    Bookmark Topic Watch Topic
  • New Topic