我越來越從$ json_a = json_decode數組($ filecontent,真):PHP打開值到一個數組
Array (
[meta_titles] => Array (
[0] => Just another site
[1] => Test test
[2] => This is a test
)
[tag_titles] => Array (
[0] => Test 1
[1] => Value 2
[2] => String 3
)
)
我想修改數組如下:
Array (
[meta_titles] => Array (
Just another site => Just another site
Test test => Test test
This is a test => This is a test
)
[tag_titles] => Array (
Test 1 => Test 1
Value 2 => Value 2
String 3 => String 3
)
)
因此,數值成爲關鍵。有人會有想法嗎?
編輯:到目前爲止我的代碼:
$json_a = json_decode($filecontent, true);
$newjson = array();
foreach($json_a as $category) {
$newjson[$category] = array_combine(array_values($category), $category);
}
$json = json_encode($newjson, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
非常感謝
EUH你的鏈接使我對「什麼是‘1’在一個PHP的print_r語句的結束意味着?」這與問題無關。 – scrybs
Wups是的,不知何故,我沒有複製正確的鏈接。我的意思是這一個:http://stackoverflow.com/q/5422955/3933332只是使用相同的子數組的鍵和值。 – Rizier123