If you are sure that both array will contain the same number separeted by comma, use this:
Version 1 (testing with 100000 takes ~0.08s, +-4x faster)
<?php
$Array1 = "FirstName, LastName, Email";
$Array2 = "John, Doe, [email protected]";
$Array1 = explode(',', preg_replace('/\s*,\s*/',',',$Array1)); //remove spaces before and after comma
$Array2 = explode(',', preg_replace('/\s*,\s*/',',',$Array2));
if(count($Array1) == count($Array2)) {
$result = array_combine($Array1, $Array2);
}
print_r($result);
Output:
Array (
[FirstName] => John
[LastName] => Doe
[Email] => [email protected]
)
Alternative version from @castis (testing with 100000 takes ~0.3s)
$Array1 = explode(',',$Array1);
$Array2 = explode(',',$Array2);
$result = array_combine(array_map('trim', $Array1), array_map('trim', $Array2));
print_r(array_combine(explode(', ',$Array1),explode(', ',$Array2)));