php - preg_match_all: changing the string $match -


so far: i'm doing preg_match_all search , output is: donald, daisy, huey, dewey , louie

code this:

$duckburg = array(); preg_match_all($pattern,$subject,$match); $duckburg['residents'] = $match[1]; print_r($duckburg['residents']); 

output:

array ( [residents] => array ( [0] => donald [1] => daisy [2] => huey [3] => dewey [4] => louie ) 

my question: add every string " duck"

using help-string: $lastname = " duck"

the output should be:

array ( [residents] => array ( [0] => donald duck [1] => daisy duck [2] => huey duck [3] => dewey duck [4] => louie duck )  

i tried (but it's not working):

preg_match_all($pattern,$subject,$match); $matchy = $match.$lastname; $duckburg['residents'] = $matchy[1]; print_r($duckburg['residents']); 

is possible change matching string before goes array? thank help!

array_map tool such manipulation:

$match = array ( 'residents' => array ('donald','daisy','huey','dewey','louie')); $duckburg['residents'] = array_map(function($n) { return "$n duck"; }, $match['residents']); var_dump($duckburg); 

output:

array(1) {   ["residents"]=>   array(5) {     [0]=>     string(11) "donald duck"     [1]=>     string(10) "daisy duck"     [2]=>     string(9) "huey duck"     [3]=>     string(10) "dewey duck"     [4]=>     string(10) "louie duck"   } } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -