我有一組DATA,我只想拿最後一組
DATA:
$data_val = {"001":{"data_1_1":["content1_1,content1_2"],"data_1_2":["content1_3,content1_4"]},"002":{"data_2_1":["content2_1"],"data2_2":["content2_2"]}}
我把他 JSON_decode
$data_val = JSON_decode($data_val, true);
JSON_decode DATA:
Array ( [001] => Array ( [data_1_1] => Array ( [0] => content1_1 [1] => content1_2)[data_1_2] => Array ( [0] => content1_3 [1] => content1_4) ) [002] => Array ( [data_2_1] => Array ( [0] => content2_1 [1] => content2_2 ) ) )
如果用 $data_val[002] 可以拿到
"Array ( [data_2_1] => Array ( [0] => content2_1 [1] => content2_2 )",
我想完整的拿到這個字串是有"[002] =>" ,如下:
[002] => Array ( [data_2_1] => Array ( [0] => content2_1 [1] => content2_2 )
應該怎樣做
<?php
$data_val = '{"001":{"data_1_1":["content1_1,content1_2"],"data_1_2":["content1_3,content1_4"]},"002":{"data_2_1":["content2_1"],"data2_2":["content2_2"]}}';
$data_val = JSON_decode($data_val, true);
var_dump([
end(array_keys($data_val)) => end($data_val)
]);
輸出是
array(1) {
["002"]=>
array(2) {
["data_2_1"]=>
array(1) {
[0]=>
string(10) "content2_1"
}
["data2_2"]=>
array(1) {
[0]=>
string(10) "content2_2"
}
}
}
不太清楚你的目的,但硬做的話就是這樣
覺得有點臭就是了 哈哈