3

the array:

('abc', 'def', 'xyz')

foreach($arr as $item)
  // change $item here

Can I do this without creating a intermediate array?

1
  • ...although in almost all cases I'd argue that reducing side-effects only increases program readability... Commented Jun 15, 2011 at 3:00

1 Answer 1

10

Use a reference.

foreach($arr as &$item)
Sign up to request clarification or add additional context in comments.

1 Comment

can explain your solution with an example? I was not able to get clear idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.