Implode array with array of glue strings



PHP Snippet 1:

echo vsprintf("John has a %s and a %s!", array('slingshot', 'potato'));

PHP Snippet 2:

John has a slingshot and a potato!

PHP Snippet 3:

$a = [0 => "John has a", 1 => "and a", 2 => "!" ];
$b = [0 => "Slingshot", 1 => "Potato"];
vsprintf(implode(" %s ", $a),$b);

PHP Snippet 4:

$a = [0 => "John has a", 1 => "and a", 2 => "!" ];
$b = [0 => "Slingshot", 1 => "Potato"];

$data = [];
foreach(array_map(null, $a, $b) as $part) {
    $data = array_merge($data, $part);
}
echo implode(" ", $data);

PHP Snippet 5:

$data = array_reduce(array_map(null, $a, $b), function($a,$b){
    return  array_merge($a, $b);
},array());

echo implode(" ", $data);

PHP Snippet 6:

 John has a Slingshot and a Potato !  

PHP Snippet 7:

$a = [0 => "John has a ", 1 => "and a", 2 => "!" ];
$b = [0 => "Slingshot", 1 => "Potato"];

foreach($a AS $k=>$v){
    echo trim($v).' '.trim($b[$k]).' ';
}