我有包含这些值的数据阵列:如何用数组中的字符串替换子字符串使用preg_replace? (PHP)
Array
(
[id] => 1
[myid] => 9
[date] => 2014-01-30
[user] => 17
[reason] => some text here...
)
这串包含数字参照数据数组索引:
$columns = '(0) as "id",(1) as "myid",(2) as "date",(3) as "user",(4) as "reason"';
是否有可能改变封闭在数字括号,包括括号从数组中取适当的值?
我知道如何与(string) preg_replace((array) $patterns, (array) $replacements, (string) $subject)
一起工作,但完全不知道如何解决这个问题。
理想的结果字符串看起来是这样的:
'1' as "id",'9' as "myid",'2014-01-30' as "date",'17' as "user",'some text here...' as "reason"
看看[array_walk()](http://php.net/manual/en/function.array-walk.php)或[array_reduce()](http://php.net) /manual/en/function.array-reduce.php)构建一个单一的字符串。 –
你为什么要这样的结果?它是为了什么? –
为什么你需要改变字符串,为什么不从数组中新的字符串? –