Jump to content

preg_replace with an array


mapleleaf

Recommended Posts

http://us.php.net/manual/en/function.array-map.php

 

Something like..

 

function replace($item){
     return preg_replace("/($item)/i","lemon");
}

$arr = array("apple","peach");
$new_arr = array_map("replace",$arr);

 

I also believe this could work:

 

$replace = preg_replace("/($value)/i","lemon");
$arr = array("apple","peach");
$new_arr = array_map($replace,$arr);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.