Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

replace strings in array without loop

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But is there another solution ?

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading