我有一个包含不同图像文件的数组,它们只包含图像文件名。我想在该数组中的每个文件名之前添加一个url。 例如:
$imgUrls = array(
'ptSignature' => '5668695879dc84.35037895.png',
'pSignature' => '5668694f80aa55.79055562.png',
'witness1Signature' => '5668695875c6e5.03917128.png',
'witness2Signature' => '5668695879dc84.35037895.png',
);
我希望他们这样:
$imgUrls = array(
'ptSignature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
'pSignature' => 'http://website-link.com/?page=gf_signature&signature=5668694f80aa55.79055562.png',
'witness1Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695875c6e5.03917128.png',
'witness2Signature' => 'http://website-link.com/?page=gf_signature&signature=5668695879dc84.35037895.png',
);
我如何管理?
答案 0 :(得分:1)
$imgUrls = array(
'ptSignature' => '5668695879dc84.35037895.png',
'pSignature' => '5668694f80aa55.79055562.png',
'witness1Signature' => '5668695875c6e5.03917128.png',
'witness2Signature' => '5668695879dc84.35037895.png',
);
$imgUrls = array_map(function($el) {
return 'http://website-link.com/?page=gf_signature&signature=' . $el;
}, $imgUrls);
var_dump($imgUrls);
答案 1 :(得分:1)
您可以使用:
foreach($imgUrls as $key=>$value)
{ $imgUrls[$key] = 'http://website-link.com/?page=gf_signature&signature=' . $value; }