7

I have data like this in my array first_name, last_name,....

I am looking for an array to replace the _ with a space..is this possible?

I took alook at http://php.net/manual/en/function.array-replace.php but I am not sure if this is what I want.

1

2 Answers 2

19

Just with str_replace, it takes either strings or arrays in all arguments that matter:

var_dump(str_replace('_',' ',array('foo_bar','lorem_ipsum')));


array(2) {
  [0]=>
  string(7) "foo bar"
  [1]=>
  string(11) "lorem ipsum"
}
Sign up to request clarification or add additional context in comments.

Comments

10
foreach($array as $key=>$value){
  $array[$key]=str_replace("_"," ",$value);
}

That should do it, right?

Comments

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.