php - replace text in associative array with text from another array -


i have array so

$tags =   array (    [0] => array     (         [0] => [first_name] [last_name]         [2] => [city],[state] [zipcode]     )   ) 

i have list so

$array_list =     [0] => array     (         [first_name] => bob         [last_name] => johnson         [city] => mycity         [state] => ny         [zipcode] => 911564     )  [1] => array     (         [first_name] => john         [last_name] => doe         [city] => new york         [state] => ny         [zipcode] => 9115      )  [2] => array     (         [first_name] => james         [last_name] => belt         [city] => los angeles         [state] => ca         [zipcode] => 915456     ) 

i want replace tags inside of brackets actual value array. tried following seems returning single value correctly

 foreach($tags $key=>$value) {      $data[$key] = preg_replace_callback('/[\[|<](.*)[\]\)]/u', 'replace_text', $value);  }     function replace_text($matches) {     foreach ($array_list $arg) {        return $args[$matches[1]];      }            } 

im getting 1 result looks so

array (    [0] => array     (         [0] => bob johnson         [1] => mycity,ny 911564     )  ) 

how can results in array correct values

i tried change function replace_text set values array , return array

 function replace_text($matches) {     foreach ($array_list $arg) {        $new_array[]= $args[$matches[1]];      }           return $new_array;    } 

but returns

 array ( [0] => array     (         [0] => array array         [1] => array         [2] => array,array array     )   ) 

i should add content dynamic 1 time may [first_name] , next [name_first] or somethign else why need fine brackets in each , replace text inside of brackets matches array.

what think this:

$output = array(); foreach($array_list $arraykey => $array) {      foreach($tags[0] $tagkey => $tag)         $output[$arraykey][$tagkey] = preg_replace_callback('/[\[|<](.*)[\]\)]/u', 'replace_text', $tag); }  function replace_text($matches) {     global $arraykey, $array_list;     return $array_list[$arraykey][$matches[1]]; } 

if it's not you, can show expected $output?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -