0

I have an array like this:

$myArray = array("Value 1", "Value 2");

Now I would like to do a "str_replace", but for an array? How ?

My idea: A foreach loop to get all values, do the str_replace and save the new value to the same array position.

But is there another solution ?

1
  • 1
    Input/Output example would be nice for clarity. I presume you will also need to consider overlapping replacements. Commented Nov 24, 2021 at 17:42

1 Answer 1

2

You can supply the array as an argument to str_replace() and it will return an array of the replaced strings:

$newArray = str_replace('Value', 'NewValue', $myArray);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.