title: Dinamic parsing variables to array_map
body: <p>I have this function </p>
  
  <pre><code>    public function saveVariantValue($id, $data, $langs, $field, $client)
      {
          $transformation = [];
          $parts1 = explode(';', $data[$field][1]);
          $parts2 = explode(';', $data[$field][2]);
  
          $tmp_arr = array_map(null, $parts1, $parts2);
          $transformation[] = array_map(
              function($v) { return array_combine(["1","2"], $v); }, 
              $tmp_arr
          );
          //here i use the transformation array//
      }
  </code></pre>
  
  <p>the function transform an input array from this, </p>
  
  <pre><code>[
    {
        "1": "tag_es1;tag_es2;tag_es3",
        "2": "tag_en1;tag_en2;tag_en3"
    }
  ]
  </code></pre>
  
  <p>to this</p>
  
  <pre><code>[
    {
      {
        "1" : "tag_es1",
        "2" : "tag_en1"
      },
      {
        "1" : "tag_es2",
        "2" : "tag_en2"
      },
      {
        "1" : "tag_es3",
        "2" : "tag_en3"
      }
    }
  ]
  </code></pre>
  
  <p>each <code>1</code> and <code>2</code> represent a language id from the database, if you check the code, it will only work if i send both languages, but in some cases based on the users permission, the user will be able to send </p>
  
  <pre><code>[
    {
        "1": "tag_es1;tag_es2;tag_es3"
    }
  ]
  </code></pre>
  
  <p>i want to make the code mode dynamically so instead of declaring <code>parts1</code> and <code>parts2</code> i could create a string of values and then eval the string like this</p>
  
  <pre><code>$str  = '';
  $eval = '';
  foreach($langs as $l) {
      //i create the string "variables", the values of the "parts" must be an array, that's why the explode
      $str  .= 'parts'.$l-&gt;id.'='.serialize(explode(";", $variant[$l-&gt;id])).';&amp;';
      //i need to pass the "parts" to array_map so i create a string to pass it as the function parameters;
      $eval .= '$parts'.$l-&gt;id.', ';
  }
  $str  = rtrim($str, '&amp;');
  $eval = rtrim($eval, ', ');
  parse_str($str);
  //if i var_dump $parts1 or $parts2 i get the correct values
  $tmp_arr = array_map(null, eval($eval));//here i fail
  </code></pre>
  
  <p>so far when i call array_map it fails throwing <code>syntax error, unexpected end of file</code></p>
  
  <p>so here goes the question, how can i make this code work? and it is ok to do this? is there a better way of doing it?</p>