我想用'BAZ'數組中的數組替換'BLOCKS'數組中的'baz'值,這些數組的標題匹配。用數組替換PHP關聯數組值(字符串)
我試過爆炸BLOCKS ['baz'],然後循環遍歷結果,並做一個str_replace無濟於事。我確信有一個更簡潔和直接的解決方案。
請參閱我想要完成的底部的DESIRED OUTPUT。非常感謝!
BLOCKS
array
0 =>
array
'foo' => string 'block1' (length=6)
'bar' => string '/uploads/commercial/pdf.pdf' (length=27)
'baz' => string '372|371' (length=7)
1 =>
array
'foo' => string 'block2' (length=6)
'bar' => string '/uploads/commercial/pdf.pdf' (length=27)
'baz' => string '371' (length=3)
BAZ
array
372 =>
array
'wibble' => string 'building2' (length=9)
'wobble' => int 235000
'wubble' => string 'office|medical' (length=14)
371 =>
array
'wibble' => string 'building1' (length=9)
'wobble' => int 252000
'wubble' => string 'office' (length=6)
DESIRED OUTPUT
array
0 =>
array
'foo' => 'block1'
'bar' => '/uploads/commercial/pdf.pdf'
'baz' => array(
372 =>
array
'wibble' => string 'building2' (length=9)
'wobble' => int 235000
'wubble' => string 'office|medical' (length=14)
371 =>
array
'wibble' => string 'building1' (length=9)
'wobble' => int 252000
'wubble' => string 'office' (length=6)
);
1 =>
array
'foo' => string 'block2' (length=6)
'bar' => string '/uploads/commercial/pdf.pdf' (length=27)
'baz' => array(
371 =>
array
'wibble' => string 'building1' (length=9)
'wobble' => int 252000
'wubble' => string 'office' (length=6)
)
);
請新增到目前爲止你已經嘗試了代碼開發高級。 – Marc 2012-03-07 00:46:43