How do I replace each item, without changing array's structure?

tammyelectric

New Member
\[code\]$array = array('lastname', 'email', 'phone');\[/code\]How do I run \[code\]foreach\[/code\] for this array and write updated value to its place?Like:\[code\]foreach ($array as $item) { // do something // replace old value of this item with a new one}\[/code\]Example:\[code\]foreach ($array as $item) { if (item == 'lastname') $item = 'firstname'; // replace current $item's value with a 'firstname'}\[/code\]Array should become:\[code\]$array = array('firstname', 'email', 'phone');\[/code\]
 
Back
Top